There is an [electron framework](https://electron.atom.io/) that gives you a stripped down browser to build your user interface for the desktop application. In my case, I am using `jQuery` for DOM navigation, `Sequelize` to talk to my sqlite database and a couple other libraries.

Let's say I have a text field where the user can type a movie name. My database stores a couple hundred movie names. So I would like to offer the user autocomplete suggestions.

Typically, I would use something like this to register a `jQuery` handler (this will echo field input back to console):

```
$('#movie-search-field').on('input', (event) => {
    console.log(event.target.val())
})

```

With sequelize, you would typically have a model (say, `Movie`) and query it like so: `Movie.findAll()`. Here comes the problem:

If I register my handler like so:

```
Movie.findAll().then((movies) => {
    $('#movie-search-field').on('input', (event) => {
        /*Use movies here to build and show a suggestions list*/
    })
})

```

then it never gets triggered. I have verified that the `.then` clause is entered by printing `movies` to console from within it.

On the other hand, if I try to query the database from inside the handler:

```
$('#movie-search-field').on('input', (event) => {
    Movies.findAll().then((movies) => {
        /*Use movies to build and show a suggestions list*/
    })
})

```

then the handler exits before the promise is resolved and no suggestions are shown.

How could I use the database query results in my event handler?