I am wondering if when running pg-co with node express server, do you connect to the database on every client connection? or keep a global connection?
Reference: https://github.com/basicdays/co-pg
In other words, here is my node module:
module.exports.set = function(app, worker_id) {
var ms = require("mslibmod"),
co = require('co'),
async = require('async'),
pgconn = require('pgconn').create(),
pg = require('co-pg')(require('pg')),
exec = require('co-exec'),
thunkify = require('thunkify');
app.get('/getLines', function(req, res, next) {
var id = req.param('id');
co(function*() {
try {
var pgHandle = yield pg.connect_(pgconn.dbserver('galaxy'));
var statement = 'select business_name FROM business_info WHERE business_id = ' + '1016';
var result = yield pgHandle[0].query_(statement);
pgHandle[1](); // pg queue done
if (result.rows[0] == undefined){}
ms.log(result.rows[0].business_name);
} catch (e) {
console.error('Panic: ' + e.toString());
}
})();
res.send({});
});
};
notice how I run the command:
var pgHandle = yield pg.connect_(pgconn.dbserver('galaxy'));
everytime a new express client is connected, is this the correct approach? wouldn't lead to memory leaks?