Wednesday, 5 September 2018

Question on Knex

It seems that Knex can return two different things for a query. Taking for example:function read () { return knexTest .select('*') .from('rental') .leftJoin('customer', 'rental.customer_id', 'customer.customer_id') .whereIn('rental_id', [2,3]); } console.log(read()); Looks like the console.log(read()); prints out some metadata about the connection and query - https://ift.tt/2wN1vbn only way I've found to print out the actual query results is to chain then to the promise outside the function and print the data that's passedfunction read () { return knexTest .select('*') .from('rental') .leftJoin('customer', 'rental.customer_id', 'customer.customer_id') .whereIn('rental_id', [2,3]); } read().then(x => console.log(x)); Here, you get the actual data like - https://ift.tt/2Q8YUl0 question is how do you return the query results from inside the function? I want read() to already return the query results. Many thanks!Edit: I've tried resolving the promise from inside the function and storing the results in a variable and then attempted to return the variable and I can't get it to work.

Submitted September 05, 2018 at 06:24PM by professor-cthulhu

No comments:

Post a Comment