2

First of all I carefully read the documentation here and checked similar StackOverflow questions. I have a sequence of SQL requests. When I write this, everything works fine:

  const { rows } = await db.query(`
    SELECT *  FROM table
    WHERE id = ${id}`)

But I'd like to make several requests, that's why I thought about writing this:

  let rows;

  { rows } = await db.query(`
    SELECT *  FROM table
    WHERE id = ${id}`)

  // do something with the rows

  { rows } = await db.query(`
    SELECT *  FROM othertable
    WHERE id = ${id}`)

  // do something else

But I have this error:

  { rows } = await db.query(`
         ^
SyntaxError: Unexpected token '='

Seeing the documentation, it appears to be a simple assignment, I don't know what is wrong with this. Any help would be very kind :)

1
  • 1
    Also, as an alternative to destructuring rows = (await db.query(/* ... */)).rows Commented Jan 20, 2021 at 15:04

1 Answer 1

2

({rows} = await db.query(...))

you should use parenthesis to signal it's not a block but an assignment

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.