Skip to content

Commit df1f350

Browse files
author
Aurynn Shaw
committed
Transactions (basically) seem to work. No immediate side-effects to using transaction objects, or doing multiple queries in a given TX context.
Added a basic test-case as t/transaction.js
1 parent 13041fb commit df1f350

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

t/transaction.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
var sys = require("sys");
2+
var pg = require("../lib/postgres-pure");
3+
pg.DEBUG=0;
4+
5+
var db = new pg.connect("pgsql://test:12345@localhost:5432/template1");
6+
db.transaction(function (tx) {
7+
tx.begin();
8+
tx.query("CREATE TABLE insert_test (id serial not null, val text)", function (err, rs) {
9+
// Null query.
10+
});
11+
tx.query("INSERT INTO insert_test (val) VALUES (?) RETURNING id", "test value", function (err,rs) {
12+
console.log(sys.inspect(rs));
13+
});
14+
tx.prepare("INSERT INTO insert_test (val) VALUES (?) RETURNING id", function (sth) {
15+
sth.execute("twooooo", function (err, rs) {
16+
console.log(sys.inspect(rs));
17+
});
18+
});
19+
tx.rollback();
20+
tx.query("SELECT * FROM insert_test", function (err, rs) {
21+
// Should error
22+
console.log(sys.inspect(err));
23+
});
24+
});
25+
db.close();

0 commit comments

Comments
 (0)