Node-postgres: anonymous rows in Node 6

Created on 23 Jun 2016  ·  10Comments  ·  Source: brianc/node-postgres

Any idea why starting from Node.js 6 we are getting data rows with anonymous in front?

I mean, the Result object looks like this in the console:

{ command: 'SELECT',
  rowCount: 1,
  oid: NaN,
  rows: [ anonymous { id: 1, login: 'user-1', active: true } ]

And if we print a single row:

console.log(result.rows[0]);
//=>
// anonymous { id: 1, login: 'user-1', active: true }

What is that anonymous thing and why is it there?

Most helpful comment

It seems to me that it is no actual change, only in console.log. Try using console.log(JSON.stringify(result)). It does not change the effect of any code.

All 10 comments

I think it's a change to V8 that logs the constructor of objects when you log them. Because I use an anonymous class when I parse rows into the JS object, I guess V8 is logging it as such. Basically some kinda internal V8 change that can be ignored. There might be some kinda setting somewhere to toggle this behavior off in node - not sure about it. Good question though, I noticed the same thing. 😄

I got this question for pg-promise, tried to figure out, couldn't, forwarded it here.

I know it is cosmetic, and happens only starting from Node.js 6.x

But of you think you can easily get rid of it - please do, to avoid this being re-asked in the future ;)

So... solution is to not use Node 6? or figure out the V8 internals?

You could look at how node logs objects with console.log and see if there's an option there.

It seems to me that it is no actual change, only in console.log. Try using console.log(JSON.stringify(result)). It does not change the effect of any code.

This does not affect only console logs. I am using assert.deepStrictEqual to compare resultsets returned from database to some expected datasets, and after switching to postgres started getting failing asserts when comparing [ anonymous { count: '0' } ] to [{ count: '0' } ]

resultset.map(row => Object.assign({}, row)) fixes failing assert for me.

Node 8.6.0

Is there any fix regarding this problem?
I have the same problem when trying to access a specific row from a query using rows.forEach and I can't parse my data as a result.

client.query(MY QUERY)
.then((res) => {
  res.rows.forEach((value) => {
    console.log(value)
  })
})

Returns:

anonymous {
  collection_id: 1,
  user_id: 1,
  card_id: 'card_id_example',
  init_price: 50,
  number_of_card: 1,
  date_buy: '2018-2-5',
  last_update: '2018-2-5' }

@tgibralta You’re parsing the output of console.log?

I am not parsing the output of the console, I want to parse the data itself (the value)
But when I try to do so, I get the anonymous in front of the JSON object, which is kind of problematic

@tgibralta No JSON is involved; rows are objects. If you log JSON.stringify(value), “anonymous” won’t show up anywhere.

Was this page helpful?
0 / 5 - 0 ratings