Thursday 26 March 2020

How does Knex know that the function is the last function in the chain

Hi, I was wondering how knex runs it's queries ?to query user data I can write my query in two ways: await knex.from("users").select("id", "label") await knex.select("id", "label").from("users") and both give me same results. I was wondering how knex know that it is the last function and runs the query against the database.I only know the way to add a execution function, something like this:await db.select("id", "label").from("users").run()``` let sql = { select: [], from: [], where: [], group: [], having: [], order: [], LIMIT: false }export default { select(...args) { sql.select.push(args) return this }, from(...args) { sql.from.push(args) return this }, run() { let query = ""query += " SELECT " + sql.select query += " FROM " + sql.from console.log(query) } } ```Can anyone explain this to me ? Thx!

Submitted March 26, 2020 at 10:02AM by style-112

No comments:

Post a Comment