-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy pathexample.js
33 lines (26 loc) · 1.04 KB
/
example.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
var pg = require('../lib/index.js');
var config = {
host: 'localhost',
user: 'postgres', //env var: PGUSER
database: 'postgres', //env var: PGDATABASE
password: null, //env var: PGPASSWORD
port: 5432, //env var: PGPORT
max: 10, // max number of clients in the pool
idleTimeoutMillis: 30000, // how long a client is allowed to remain idle before being closed
multipleStatementResult : true
};
var client = new pg.Client(config);
// connect to our database
client.connect(function (err) {
if (err) throw err;
// execute a query on our database
client.query('DELETE FROM users WHERE id = 1;SELECT * FROM users;select * from events;update users set id = 1 where id = 1; INSERT INTO users(id,email,name) values(332,\'[email protected]\',\'test user\');', function (err, result) {
if (err) throw err;
// just print the result to the console
console.log(result.rows[0]);
// disconnect the client
client.end(function (err) {
if (err) throw err;
});
});
});