Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why select result return an array of RowDataPacket? #1330

Closed
vthai opened this issue Jan 13, 2016 · 2 comments
Closed

Why select result return an array of RowDataPacket? #1330

vthai opened this issue Jan 13, 2016 · 2 comments
Assignees
Labels

Comments

@vthai
Copy link

vthai commented Jan 13, 2016

I am wondering why the query result for a SQL SELECT return something like this:

[ RowDataPacket {
        id: 19,
        username: 'admin',
        status: 1,
        role: 2,
        phone: '123456789',
        first_name: 'admin',
        last_name: 'admin' },
      RowDataPacket {
        id: 23,
        username: 'abhjj',
        status: 1,
        role: 2,
        phone: '123456789',
        first_name: 'admin',
        last_name: 'admin' },
      RowDataPacket {
        id: 24,
        username: 'abheee',
        status: 1,
        role: 2,
        phone: '123456789',
        first_name: 'admin',
        last_name: 'admin' } ] 

Shouldn't it just return something a "pure" JSON array like this:

[{"id":19,"username":"admin","status":1,"role":2,"phone":"123456789","first_name":"admin","last_name":"admin"},{"id":23,"username":"abhjj","status":1,"role":2,"phone":"123456789","first_name":"admin","last_name":"admin"},{"id":24,"username":"abheee","status":1,"role":2,"phone":"123456789","first_name":"admin","last_name":"admin"}]

Maybe I am new to Javascript but the one returned by node-mysql doesn't even qualified as JSON object? no colon after RowDataPacket?

@dougwilson dougwilson self-assigned this Jan 13, 2016
@dougwilson
Copy link
Member

Hi @vthai ! We return an array of RowDataPacket objects because this is a low-level driver library. But regardless, the output you provided above is not JSON because you didn't use a JSON serializer to display it. It looks like you probably used console.dir or console.log, which Node.js uses a different formatting.

Try using this: console.log(JSON.stringify(result))

@sidorares
Copy link
Member

It might actually help with performance as well. Because all rows are instances of the same RowDataPacket class, they all share same 'hidden class' - see for example http://s3.mrale.ph/nodecamp.eu/#41 for explanation

@mysqljs mysqljs deleted a comment from ZeroHackeR Jun 21, 2018
@mysqljs mysqljs locked as resolved and limited conversation to collaborators Jun 21, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

No branches or pull requests

3 participants