Skip to content

Commit 2f85465

Browse files
committed
updated readme to better reflect row api
1 parent c88aa5d commit 2f85465

File tree

1 file changed

+29
-9
lines changed

1 file changed

+29
-9
lines changed

README.md

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,28 +40,48 @@ fully TDD and with lots of love.
4040

4141
client.connect();
4242
client.on('drain', client.end.bind(client));
43-
44-
var printRow = function(row) {
45-
console.log(row);
46-
};
47-
43+
44+
//queries are queued on a per-client basis and executed one at a time
45+
client.query("create temp table user(heart varchar(10), birthday timestamptz);");
46+
47+
//parameters are always parsed & prepared inside of PostgreSQL server
48+
//using unnamed prepared statement (no sql injection! yay!)
49+
client.query({
50+
text: 'INSERT INTO user(heart, birthday) VALUES ($1, $2)',
51+
values: ['big', new Date(2031, 03, 03)]
52+
});
53+
client.query({
54+
text: 'INSERT INTO user(heart, birthday) VALUES ($1, $2)',
55+
values: ['filled with kisses', new Date(2010, 01, 01)]
56+
});
57+
4858
var simpleQuery = client.query("select * from user where heart = 'big'");
49-
simpleQuery.on('row', printRow);
59+
simpleQuery.on('row', function(row){
60+
console.log(row.heart); //big
61+
console.log(row.birthday.getYear()); //2031
62+
});
5063

5164
var preparedStatement = client.query({
5265
name: 'user by heart type',
5366
text: 'select * from user where heart = $1',
5467
values: ['big']
5568
});
56-
preparedStatement.on('row', printRow);
69+
70+
preparedStatement.on('row', function(row){
71+
console.log(row.heart); //big
72+
console.log(row.birthday.getYear()); //2031
73+
});
5774

5875
var cachedPreparedStatement = client.query({
5976
name: 'user by heart type',
60-
//you can omit the text the 2nd time, but you don't have to
77+
//you can omit the text the 2nd time if using a named query
6178
values: ['filled with kisses']
6279
});
63-
cachedPreparedStatement.on('row', printRow);
6480

81+
cachedPreparedStatement.on('row', function(row){
82+
console.log(row.heart); //filled with kisses
83+
console.log(row.birthday.getYear()); //2010
84+
});
6585

6686
### Philosophy
6787

0 commit comments

Comments
 (0)