I was trying to fetch the data from postgres sql using nodejs.
I have been using npm pg to establish the connection to database. Using select query trying to fetch all the data from postgres but PostgreSQL returns the data in anonymous block.
I was unable to get the data from anonymous block. If try to get the data it returns as undefined.
Can anyone please help me out? Please see my output
anonymous {
Id: 10062,
Animal: 'horse',
Breed: 'American Quarter',
Age: 'Adult',
Sex: 'male',
Size: 'Medium',
Color: 'Green',
Status: 'Homestay'
},
From this I want to get the Breed alone, but it does not affect my functionality, bu unable to get the individual value from the block please see my code below:
function selectAllRecords{
/**
* pool is my connection object,initiall a pool of connection is created
* This function fetch all the records from the table
*/
pool.connect(function(err, client, done) {
if(err) {
return console.error('error fetching client from pool', err);
}
client.query('select * from petpoint', function(err, result) {
done();
if(err) {
return console.error('error running tracking table query', err);}
console.log(result.rows); //output will be in postgres anonymous block
console.log(result.rows.Id) //undefined
console.log(result.rows.anonymous.Id) //undefined
});
});
pool.on('error', function (err, client) {
console.error('idle client error', err.message, err.stack)
})
}