Skip to content

Commit b6af692

Browse files
committed
updated readme
1 parent a2f7ca3 commit b6af692

File tree

1 file changed

+67
-26
lines changed

1 file changed

+67
-26
lines changed

README.md

Lines changed: 67 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,34 @@
11
#node-postgres
22

3-
Non-blocking PostgreSQL client for node.js
4-
5-
* a pure javascript client and native libpq bindings with _the same api_
6-
* _heavily_ tested
7-
* the same suite of 200+ integration tests passed by both javascript & libpq bindings
8-
* benchmark & long-running memory leak tests performed before releases
9-
* tested with with
10-
* postgres 8.x, 9.x
11-
* Linux, OS X
12-
* node 2.x, 3.x, & 4.x
13-
* row-by-row result streaming
14-
* optional, built-in connection pooling
15-
* responsive project maintainer
16-
* supported PostgreSQL features
17-
* parameterized queries
18-
* named statements with query plan caching
19-
* async notifications
20-
* extensible js<->postgresql data-type coercion
21-
* query queue
22-
* active development
23-
* _very_ fast
24-
* No dependencies (other than PostgreSQL)
25-
* No monkey patching
3+
Non-blocking PostgreSQL client for node.js. Pure JavaScript and native libpq bindings.
264

275
## Installation
286

297
npm install pg
308

319
## Examples
3210

33-
All examples will work with the pure javascript bindings (currently default) or the libpq native (c/c++) bindings (currently in beta.) Replace `require('pg')` with `require(pg/native)` to use the libpq native (c/c++) bindings.
11+
All examples will work with the pure javascript bindings (currently default) or the libpq native (c/c++) bindings (currently in beta)
12+
13+
To use native libpq bindings replace `require('pg')` with `require(pg/native)`.
14+
15+
The two share the same interface so __no other code changes should be required__. If you find yourself having to change code other than the require statement when switching from `pg` to `pg/native`, please report an issue.
16+
17+
### Simple, using built-in client pool
18+
19+
var pg = require('pg');
20+
//or native libpq bindings
21+
//var pg = require('pg/native')
22+
23+
var conString = "tcp://postgres:1234@localhost/postgres";
24+
25+
//error handling omitted
26+
pg.connect(conString, function(err, client) {
27+
client.query("SELECT NOW() as when", function(err, result) {
28+
console.log("Row count: %d",result.rows.length); // 1
29+
console.log("Current year: %d", result.rows[0].when.getYear());
30+
});
31+
});
3432

3533
### Evented api
3634

@@ -39,22 +37,65 @@ All examples will work with the pure javascript bindings (currently default) or
3937

4038
var client = new pg.Client(conString);
4139
client.connect();
40+
4241
//queries are queued and executed one after another once the connection becomes available
43-
client.query("CREATE TEMP TABLE beatles(name varchar(10), height integer, birthday timestamptz)");
42+
client.query("CREATE TEMP TABLE beatles(name varchar(10), height integer, birthday timestamps)");
4443
client.query("INSERT INTO beatles(name, height, birthday) values($1, $2, $3)", ['Ringo', 67, new Date(1945, 11, 2)]);
4544
client.query("INSERT INTO beatles(name, height, birthday) values($1, $2, $3)", ['John', 68, new Date(1944, 10, 13)]);
45+
46+
//queries can be executed either via text/parameter values passed as individual arguments
47+
//or by passing an options object containing text, (optional) parameter values, and (optional) query name
48+
client.query({
49+
name: 'insert beatle',
50+
text: "INSERT INTO beatles(name, height, birthday) values($1, $2, $3)",
51+
values: ['George', 70, new Date(1946, 02, 14)]
52+
});
53+
54+
//subsequent queries with the same name will be executed without re-parsing the query plan by postgres
55+
client.query({
56+
name: 'insert beatle',
57+
values: ['Paul', 63, new Date(1945, 04, 03)]
58+
});
4659
var query = client.query("SELECT * FROM beatles WHERE name = $1", ['john']);
60+
4761
//can stream row results back 1 at a time
4862
query.on('row', function(row) {
4963
console.log(row);
5064
console.log("Beatle name: %s", row.name); //Beatle name: John
5165
console.log("Beatle birth year: %d", row.birthday.getYear()); //dates are returned as javascript dates
5266
console.log("Beatle height: %d' %d\"", Math.floor(row.height/12), row.height%12); //integers are returned as javascript ints
5367
});
54-
query.on('end', function() { //fired after last row is emitted
68+
69+
//fired after last row is emitted
70+
query.on('end', function() {
5571
client.end();
5672
});
5773

74+
### Info
75+
76+
* a pure javascript client and native libpq bindings with _the same api_
77+
* _heavily_ tested
78+
* the same suite of 200+ integration tests passed by both javascript & libpq bindings
79+
* benchmark & long-running memory leak tests performed before releases
80+
* tested with with
81+
* postgres 8.x, 9.x
82+
* Linux, OS X
83+
* node 2.x, 3.x, & 4.x
84+
* row-by-row result streaming
85+
* optional, built-in connection pooling
86+
* responsive project maintainer
87+
* supported PostgreSQL features
88+
* parameterized queries
89+
* named statements with query plan caching
90+
* async notifications
91+
* extensible js<->postgresql data-type coercion
92+
* query queue
93+
* active development
94+
* fast
95+
* No dependencies (other than PostgreSQL)
96+
* No monkey patching
97+
* Tried to mirror the node-mysql api as much as possible for future multi-database-supported ORM implementation ease
98+
5899
### Contributors
59100

60101
Many thanks to the following:

0 commit comments

Comments
 (0)