0

SQL statement 1

const [rows, fields] = await pool.query("SELECT * FROM accounts WHERE username = ?", username);
console.log(rows);
return rows

SQL statement 2

const [rows, fields] = await pool.query("SELECT * FROM accounts WHERE id = ?", id);
console.log(rows)
return rows

It is the same database but the result I am getting back is displayed differently.

For the query for username,

[
  TextRow {
    id: 8,
    username: 'testing',
    password: '-',
    aws_id: '-',
    timestamp: 2020-02-23T23:38:06.000Z
  }
]

For the query by id

{
  '0': TextRow {
    id: 8,
    username: 'testing',
    password: '-',
    aws_id: '-',
    timestamp: 2020-02-23T23:38:06.000Z
  }
}

Why is it that when I am querying with ID, there is a "0" key appended to it.

1 Answer 1

2

Its possible that because id is unique, the results will never be a list of items, and "whatever you're using to connect to mysql" automatically formats for that.

some browsers also routinely add indexes to json that arent actually in the data. make sure you're not following a false-positive here and use "raw data" to view it

"JSON view"

"Raw Data view"

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

2 Comments

I’m printing out the result from console.log. Not sure if it will make a difference.
me neither. the result isn't even (valid) JSON, its just something to keep in mind - the print of a data structure isnt necessarily exactly as it exists in memory. Can you provide info on your db connector for further analysis?

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.