-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
79 lines (60 loc) · 1.44 KB
/
index.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
'use strict';
var pg = require('pg.js');
var create = require('./lib/create');
var rollback = require('./lib/rollback');
function pgTiles(connString) {
if (!(this instanceof pgTiles)) {
return new pgTiles(connString);
}
this.connectionString = connString;
}
pgTiles.prototype.query = function(sql, callback) {
var connString = this.connectionString;
pg.connect(connString, function(err, client, done) {
function handelError(err) {
done(client);
return callback(err);
}
if (err) {
return handelError(err);
}
client.query(sql, function(error, result) {
if (error) {
return handelError(error);
}
done();
return callback(null, result);
});
});
}
pgTiles.prototype.create = function(callback) {
var self = this;
var query = pgTiles.prototype.query;
create(function(err, sql) {
if (err) {
return callback(err);
}
query.call(self, sql, function(error, result) {
if (err) {
return callback(error);
}
return callback(null, result);
});
});
}
pgTiles.prototype.rollback = function(callback) {
var self = this;
var query = pgTiles.prototype.query;
rollback(function(err, sql) {
if (err) {
return callback(err);
}
query.call(self, sql, function(error, result) {
if (error) {
return callback(error);
}
return callback(null , result);
});
});
}
module.exports = pgTiles;