-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathquery.js
More file actions
33 lines (28 loc) · 887 Bytes
/
query.js
File metadata and controls
33 lines (28 loc) · 887 Bytes
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
/**
* Created by Nicholas Hallahan <nhallahan@spatialdev.com>
* on 10/24/14.
*/
var pg = require('pg');
var settings = require('./settings.js');
// PostGIS Connection String
var conString = "postgres://" +
settings.postgres.user + ":" +
settings.postgres.password + "@" +
settings.postgres.server + ":" +
settings.postgres.port + "/" +
settings.postgres.database;
module.exports = function(queryStr, cb) {
pg.connect(conString, function(err, client, done) {
if(err) {
console.error('error fetching client from pool', err);
}
client.query(queryStr, function(queryerr, result) {
//call `done()` to release the client back to the pool
done();
if(queryerr) {
console.error('ERROR RUNNING QUERY:', queryStr, queryerr);
}
cb((err || queryerr), (result && result.rows ? result.rows : result));
});
});
};