Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

297
Visualizações
How are KnexJS queries created? What finalizes the query?

I'm using KnexJS to create queries. I'm confused on what actually finalizes the query though.

Take for instance, this query:

knex('someTable').join('someOtherTable', 'someTable.fid', '=', 'someOtherTable.pid').select('someField');

The other way to write the query:

knex.select('someField').from('someTable').join('someOtherTable', 'someTable.fid', '=', 'someOtherTable.pid')

I don't fully understand when you would want to do Method 1 over 2, and vice versa. But what I'm really confused about is how knex "knows" when the query is done being built and the query is actually executed. Can anyone shed some light on this? It would make sense if there was some sort of .build() method at the end. But without it, I'm confused.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

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),

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda