push
travis-ci
250 of 279 relevant lines covered (89.61%)
3150.36 hits per line
1 |
const pg = require('pg');
|
7✔ |
2 |
const Promise = require("bluebird");
|
7✔ |
3 |
|
|
4 |
class Db {
|
|
5 |
constructor(config){ |
245✔ |
6 |
// prefers connection strings over objects
|
|
7 |
this.config = config.connectionString || config;
|
245✔ |
8 |
} |
|
9 |
|
|
10 |
executePreparedSql(name, text, values){ |
|
11 |
return this.execute({name,text,values}); |
31,696✔ |
12 |
} |
|
13 |
|
|
14 |
executeSql(text, values){ |
|
15 |
return this.execute({text,values}); |
14,886✔ |
16 |
} |
|
17 |
|
|
18 |
|
|
19 |
execute(query) { |
|
20 |
if(query.values && !Array.isArray(query.values))
|
46,603✔ |
21 |
query.values = [query.values]; |
31,766✔ |
22 |
|
|
23 |
var config = this.config; |
46,603✔ |
24 |
|
|
25 |
return new Promise(deferred); |
46,603✔ |
26 |
|
|
27 |
|
|
28 |
function deferred(resolve, reject) { |
7✔ |
29 |
|
|
30 |
pg.connect(config, (err, client, done) => { |
46,603✔ |
31 |
if(err) {
|
46,568✔ |
32 |
reject(err); |
× |
33 |
return done();
|
× |
34 |
} |
|
35 |
|
|
36 |
client.query(query, (err, result) => { |
46,568✔ |
37 |
if(err)
|
46,519✔ |
38 |
reject(err); |
× |
39 |
else
|
|
40 |
resolve(result); |
46,519✔ |
41 |
|
|
42 |
done(); |
46,519✔ |
43 |
}); |
|
44 |
}); |
|
45 |
} |
|
46 |
} |
|
47 |
|
|
48 |
} |
|
49 |
|
|
50 |
module.exports = Db; |
7✔ |