forked from creationix/postgres-js
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathdemo.js
80 lines (75 loc) · 2.44 KB
/
demo.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
var sys = require("sys");
var pg = require("./lib/postgres-pure");
// pg.DEBUG=4;
var db = new pg.connect("pgsql://test:12345@localhost:5432/insert_test");
// db.query("SELECT 1::querytest;", function (error, rs, tx) {
// if (error) {
// console.log("Error!");
// console.log(error);
// console.log(error.code);
// }
// else {
// console.log(sys.inspect(rs));
// }
//
// tx.query("SELECT 2::int as querytest2", function (err, rs) {
// console.log(sys.inspect(rs));
// });
// tx.query("SELECT 3::qt" ,function (err, rs) {
// console.log(sys.inspect(err));
// })
// });
// db.prepare("INSERT INTO returning_test (val) VALUES (?) RETURNING id, val", function (sth) {
// sth.execute("text value", function(e, rs) {
// if (rs === undefined) {
// console.log("No data.");
// }
// else {
// console.log(sys.inspect(rs));
// }
// });
// });
// db.prepare("SELECT ?::int AS preparetest", function (sth, tx) {
// sth.execute(1, function (err, rs) {
// console.log(sys.inspect(rs));
// });
// sth.execute(2, function (err, rs) {
// console.log(sys.inspect(rs));
//
// });
// tx.prepare("SELECT ?::int AS preparetest2", function (sth) {
// sth.execute(3, function (err, rs) {
// console.log(sys.inspect(rs));
// }) ;
// });
// tx.prepare("SELECT ?::int AS preparetest2", function (sth) {
// sth.execute(4, function (err, rs) {
// console.log(sys.inspect(rs));
// }) ;
// });
// });
db.transaction(function (tx) {
tx.begin();
// tx.query("INSERT INTO insert_test (val) VALUES (?) RETURNING id", "test value", function (err,rs) {
// console.log(sys.inspect(rs));
// });
// tx.prepare("INSERT INTO insert_test (val) VALUES (?) RETURNING id", function (sth) {
// sth.execute("twooooo", function (err, rs) {
// console.log(sys.inspect(rs));
// });
// });
tx.query("SELECT 1::barrrrrr", function (err, rs) {
console.log(sys.inspect(err));
});
tx.query("SELECT 1::int as foobar", function (err, rs) {
console.log(sys.inspect(err));
});
tx.rollback();
tx.query("SELECT 1::int as foobarbaz", function (err, rs) {
console.log(sys.inspect(rs));
});
});
db.close();
// db.prepare(query, function (sth, tx) {
// sth.execute(args, callback, errback);
// })