Query with Connection Object
suggest changeThis sample uses a node-postgres client. It matches node-postgres 6 and earlier, where client.query returned a query you could listen to. In pg 7 and later, client.query(text) returns a promise and the result already contains rows.
var queryString = "SELECT name, age FROM students";
var query = client.query(queryString);
query.on("row", function (row, result) {
result.addRow(row);
});
query.on("end", function (result) {
// result.rows is available here
});
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents