OK, I was creating test data before I was calling my select, but the inserts were created asynchronously. Therefore, I was calling my select before the test data was actually created.
I implemented a solution by learning how to use async.series.
Domanda
I am using the following piece of code to retrieve a simple row using a simple select in a node.js
application using Postgresql:
client.query(sql, params, function(err, result) {
// done(); // Releasing connection to the pool
console.log(sql);
var retr;
if ( !err ) {
console.log("Row count: " + result.rows.length.toString());
if ( result.rows.length > 0 ) {
retr = new UserAccount();
parseRow(retr,result.rows[0]);
}
}
callback(retr, err);
});
Yet, no rows are returned:
SELECT * FROM "MySchema"."USER_ACCOUNT" WHERE "ID" = $1;
Retrieving user account by ID = 1
No user account found!
Row count: 0
But, the row is there in the database, I can see it with pgAdmin III. What I am doing wrong?
UPDATE: There is a callback I have just added in the code.
Soluzione
OK, I was creating test data before I was calling my select, but the inserts were created asynchronously. Therefore, I was calling my select before the test data was actually created.
I implemented a solution by learning how to use async.series.