Skip to content

Commit 9862cba

Browse files
authored
Merge pull request epost#19 from tonyd256/td-aff-4
Update to Aff 4.0
2 parents 0621274 + 86ae9a5 commit 9862cba

File tree

4 files changed

+186
-141
lines changed

4 files changed

+186
-141
lines changed

bower.json

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "purescript-node-postgres",
3-
"version": "2.0.0",
3+
"version": "4.0.0",
44
"moduleType": [
55
"node"
66
],
@@ -26,22 +26,22 @@
2626
"output"
2727
],
2828
"dependencies": {
29-
"purescript-arrays": "^4.0.0",
30-
"purescript-either": "^3.0.0",
31-
"purescript-foreign": "^4.0.0",
32-
"purescript-foldable-traversable": "^3.0.0",
33-
"purescript-transformers": "^3.0.0",
34-
"purescript-aff": "^3.0.0",
35-
"purescript-integers": "^3.0.0",
36-
"purescript-datetime": "^3.0.0",
29+
"purescript-arrays": "^4.2.1",
30+
"purescript-either": "^3.1.0",
31+
"purescript-foreign": "^4.0.1",
32+
"purescript-foldable-traversable": "^3.6.1",
33+
"purescript-transformers": "^3.4.0",
34+
"purescript-aff": "^4.0.0",
35+
"purescript-integers": "^3.1.0",
36+
"purescript-datetime": "^3.4.0",
3737
"purescript-unsafe-coerce": "^3.0.0",
3838
"purescript-nullable": "^3.0.0",
39-
"purescript-prelude": "^3.0.0",
40-
"purescript-foreign-generic": "^4.0.0"
39+
"purescript-prelude": "^3.1.0",
40+
"purescript-foreign-generic": "^5.0.0"
4141
},
4242
"devDependencies": {
43-
"purescript-spec": "^1.0.0",
43+
"purescript-spec": "^2.0.0",
4444
"purescript-generics": "^4.0.0",
45-
"purescript-js-date": "^4.0.0"
45+
"purescript-js-date": "^5.1.0"
4646
}
4747
}

src/Database/Postgres.js

Lines changed: 43 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -3,95 +3,98 @@
33

44
var pg = require('pg');
55

6-
exports["connect'"] = function (conString) {
7-
return function(success, error) {
8-
var client = new pg.Client(conString);
9-
client.connect(function(err) {
10-
if (err) {
11-
error(err);
12-
} else {
13-
success(client);
14-
}
15-
})
16-
return client;
6+
exports.mkPool = function (conInfo) {
7+
return function () {
8+
return new pg.Pool(conInfo);
179
};
1810
}
1911

20-
exports._withClient = function (conString, cb) {
21-
return function(success, error) {
22-
pg.connect(conString, function(err, client, done) {
12+
exports["connect'"] = function (pool) {
13+
return function(error, success) {
14+
pool.connect(function(err, client) {
2315
if (err) {
24-
done(true);
25-
return error(err);
26-
}
27-
cb(client)(function(v) {
28-
done();
29-
success(v);
30-
}, function(err) {
31-
done();
3216
error(err);
33-
})
17+
} else {
18+
success(client);
19+
}
3420
});
21+
return function(cancelError, onCancelerError, onCancelerSuccess) {
22+
onCancelerSuccess();
23+
};
3524
};
3625
}
3726

38-
exports.runQuery_ = function (queryStr) {
27+
exports.runQuery_ = function(queryStr) {
3928
return function(client) {
40-
return function(success, error) {
29+
return function(error, success) {
4130
client.query(queryStr, function(err, result) {
4231
if (err) {
4332
error(err);
4433
} else {
4534
success(result.rows);
4635
}
47-
})
36+
});
37+
return function(cancelError, onCancelerError, onCancelerSuccess) {
38+
onCancelerSuccess();
39+
};
4840
};
4941
};
5042
}
5143

52-
exports.runQuery = function (queryStr) {
44+
exports.runQuery = function(queryStr) {
5345
return function(params) {
5446
return function(client) {
55-
return function(success, error) {
47+
return function(error, success) {
5648
client.query(queryStr, params, function(err, result) {
5749
if (err) return error(err);
5850
success(result.rows);
59-
})
51+
});
52+
return function(cancelError, onCancelerError, onCancelerSuccess) {
53+
onCancelerSuccess();
54+
};
6055
};
6156
};
6257
};
6358
}
6459

65-
exports.runQueryValue_ = function (queryStr) {
60+
exports.runQueryValue_ = function(queryStr) {
6661
return function(client) {
67-
return function(success, error) {
62+
return function(error, success) {
6863
client.query(queryStr, function(err, result) {
6964
if (err) return error(err);
7065
success(result.rows.length > 0 ? result.rows[0][result.fields[0].name] : undefined);
71-
})
66+
});
67+
return function(cancelError, onCancelerError, onCancelerSuccess) {
68+
onCancelerSuccess();
69+
};
7270
};
7371
};
7472
}
7573

76-
exports.runQueryValue = function (queryStr) {
74+
exports.runQueryValue = function(queryStr) {
7775
return function(params) {
7876
return function(client) {
79-
return function(success, error) {
77+
return function(error, success) {
8078
client.query(queryStr, params, function(err, result) {
8179
if (err) return error(err);
8280
success(result.rows.length > 0 ? result.rows[0][result.fields[0].name] : undefined);
83-
})
81+
});
82+
return function(cancelError, onCancelerError, onCancelerSuccess) {
83+
onCancelerSuccess();
84+
};
8485
};
8586
};
8687
};
8788
}
8889

89-
exports.end = function (client) {
90-
return function() {
91-
client.end();
90+
exports.release = function (client) {
91+
return function () {
92+
client.release();
9293
};
9394
}
9495

95-
exports.disconnect = function () {
96-
pg.end();
96+
exports.end = function(pool) {
97+
return function() {
98+
pool.end();
99+
};
97100
}

0 commit comments

Comments
 (0)