1

I am writing a simple function to query my database with Knex in Node. Everything I've tried returns Promise { <pending> }

Function to query the DB:

const queryTable = async () => {
  const data = await knex
    .select("*")
    .from(TABLE_NAME)

  return data;
};

I've tried calling the function in it's own async/await wrapper, and I've tried the .then() callback after... No luck. Any leads appreciated!

Bergi
  • 630,263
  • 148
  • 957
  • 1,375
H_W
  • 35
  • 5
  • Did you try to `console.log(data)` in this function? Do you `await` the function `queryTable` where it's called? – Pompedup Nov 24 '22 at 01:16
  • "*Everything I've tried returns Promise { }*" - that's normal and expected, and unavoidable. – Bergi Nov 30 '22 at 00:15
  • "*I've tried calling the function in it's own async/await wrapper, and I've tried the .then() callback after... No luck.*" - please [edit] your question to show us what exactly you did, show us the output you got, and explain how that didn't work for you. – Bergi Nov 30 '22 at 00:16
  • There is no such thing as `async/await` wrapper. If you ever created such a wrapper you can **only** call the wrapper inside an `async` function and `await` the wrapper therefore the wrapper is not useful at all - it would be the same as using `knex` without using any wrappers. – slebetman Nov 30 '22 at 00:41

1 Answers1

-1

Try const data = await knex(TABLE_NAME).select() - does that work?

kgaspard
  • 302
  • 2
  • 10