You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+25-25
Original file line number
Diff line number
Diff line change
@@ -10,55 +10,55 @@ PostgreSQL client for node.js. Pure JavaScript and native libpq bindings.
10
10
11
11
## Examples
12
12
13
-
### Simple
13
+
### Client pooling
14
14
15
-
Connect to a postgres instance, run a query, and disconnect.
15
+
Typically you will access the PostgreSQL server through a pool of clients. node-postgres ships with a built in pool to help get you up and running quickly.
16
16
17
17
```javascript
18
-
var pg =require('pg');
19
-
//or native libpq bindings
20
-
//var pg = require('pg').native
21
-
18
+
var pg =require('pg');
22
19
var conString ="postgres://postgres:1234@localhost/postgres";
returnconsole.error('could not connect to postgres', err);
23
+
returnconsole.error('error fetching client from pool', err);
28
24
}
29
-
client.query('SELECT NOW() AS "theTime"', function(err, result) {
25
+
client.query('SELECT $1::int AS numbor', ['1'], function(err, result) {
26
+
//call `done()` to release the client back to the pool
27
+
done();
28
+
30
29
if(err) {
31
30
returnconsole.error('error running query', err);
32
31
}
33
-
console.log(result.rows[0].theTime);
34
-
//output: Tue Jan 15 2013 19:12:47 GMT-600 (CST)
35
-
client.end();
32
+
console.log(result.rows[0].numbor);
33
+
//output: 1
36
34
});
37
35
});
38
36
39
37
```
40
38
41
-
### Client pooling
39
+
### Simple
42
40
43
-
Typically you will access the PostgreSQL server through a pool of clients. node-postgres ships with a built in pool to help get you up and running quickly.
41
+
Sometimes you may not want to use a pool of connections. You can easily connect a single client to a postgres instance, run a query, and disconnect.
44
42
45
43
```javascript
46
-
var pg =require('pg');
44
+
var pg =require('pg');
45
+
//or native libpq bindings
46
+
//var pg = require('pg').native
47
+
47
48
var conString ="postgres://postgres:1234@localhost/postgres";
0 commit comments