How are KnexJS queries created? What finalizes the query?

Knex query gets triggered when it's .then() method is called. Because the async/await keyword internally calls a Promise's .then() method using the await keyword with a knex object will also finalize it. Note that Promise.all() will also try to call the .then() method of promises passed to it so Promise.all() will also finalize a knex query.

So basically knex queries gets finalized and transmitted to the database when:

  1. you call it's .then() method

  2. you use the await keyword on it

  3. you pass it to Promise.all()

But note that (2) and (3) are actually just different versions of (1),