Skip to content

Instantly share code, notes, and snippets.

@tudorilisoi
Created September 4, 2020 19:10
Show Gist options
  • Save tudorilisoi/9cdabf4f2683856faedccb103b64642c to your computer and use it in GitHub Desktop.
Save tudorilisoi/9cdabf4f2683856faedccb103b64642c to your computer and use it in GitHub Desktop.
Knex procedural sequence vs join
try {
// queries sequence
const topicIDs = await knex('topics_users').select('topic_id').where('user_id', userID)
const topics = await knex('topics').select('*').where('id', topicIDs)
//single query
const topicsInOneGo = await knex('topics').select('*')
.innerJoin('topics_users', 'topics_users.id', 'topics.id')
.where('topics_users.user_id', topicIDs)
} catch (error) {
console.log(`Oops!`, err)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment