1

this is my function. If I remove the ? and enter the info manually it executes, I would assume this is how you pass in parameters. is this correct? If i console log the params they all work, I am assuming the way the params are been passed down

async function getMultiple(page = 1){
    const offset = helper.getOffset(page, config.listPerPage);
    const rows = await db.query(
        'SELECT id, quote, author FROM quote LIMIT ?,?',
        [offset, config.listPerPage]
    );
    const data = helper.emptyOrRows(rows);
    const meta = {page};

    return {
        data,
        meta
    }
}

module.exports = {
  getMultiple
}
Samathingamajig
  • 11,839
  • 3
  • 12
  • 34
chewie
  • 529
  • 4
  • 17
  • Are you certain `helper.getOffset()` has returned a value by the time you try an use it in `db.query()`? What happens if you make it asynchronous as well and `await` its return before you proceed to the query? – dusthaines Jul 07 '21 at 17:21
  • @dusthaines yea, if i console.log offset i get a value, before it goes to db.query. its strange. – chewie Jul 07 '21 at 19:35
  • And if you console.log `config.listPerPage` you see a value as well? Your query looks ok so worth confirming that listPerPage value is coming from the config module as expected. – dusthaines Jul 07 '21 at 19:56
  • @dusthaines yea, its also returning a value before going to db.query as expected. – chewie Jul 07 '21 at 20:07

1 Answers1

0

So it turns out that the mysql version I had installed (8.0.23) has a problem with prepared statements (or a different way). I had to downgrade to less than that and it worked as expected. I downgraded to 5.7

chewie
  • 529
  • 4
  • 17