Created
September 4, 2020 19:10
-
-
Save tudorilisoi/9cdabf4f2683856faedccb103b64642c to your computer and use it in GitHub Desktop.
Knex procedural sequence vs join
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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