Search code examples
postgresqlknex.js

Simple knex query returning table name only


I am trying to work with knex to retrieve some database values however no matter the configuration I use I am either getting a 500 error code or just a pending network session. To keep it as simple as possible to get something at least working I have written the following:

export default () => (async (req, res, knex) => {
    const temp = knex('vouchers').select();
    console.log(temp);

  res.response(201).end();
});

Which should by my understanding go into my vouchers table and retrieve everything, I only end up getting a 500 errorand a console log of vouchers i.e. my table name...


Solution

  • Try:

    export default () => (async (req, res, knex) => {
      const temp = await knex('vouchers');
      console.log(temp);
      res.send(JSON.stringify(temp,null,2));
    });