var db = new pg.Client(parseConfig()); db.connect()
function createClient (cb) { setup(function () { queryable = new pg.Client({ database: 'test_elastic_apm', user: process.env.PGUSER || 'postgres' }) queryable.connect(function (err) { if (err) throw err cb() }) }) }
/* GET Postgres JSON data */ router.get('/data', function (req, res) { var client = new pg.Client(conString); client.connect(); var query = client.query(coffee_query); query.on("row", function (row, result) { result.addRow(row); }); query.on("end", function (result) { res.send(result.rows[0].row_to_json); res.end(); }); });
Object.values(routes).forEach(({ method, path, handler }) => { api[method](path, async req => { const db = new pg.Client(config.get('db')); await db.connect(); try { return await handler( dbApi(db), serverConfig, importerApi(importerSendTxEndpoint), )(req); } finally { db.end(); } }); });
operation.attempt(function() { var client = new pg.Client() client.connect(function(e) { client.end() if(operation.retry(e)) { return; } if(!e) console.log("Hello Postgres!") }) })
/* GET the filtered page */ router.get('/filter*', function (req, res) { var name = req.query.name; if (name.indexOf("--") > -1 || name.indexOf("'") > -1 || name.indexOf(";") > -1 || name.indexOf("/*") > -1 || name.indexOf("xp_") > -1){ console.log("Bad request detected"); res.redirect('/map'); return; } else { console.log("Request passed") var filter_query = "SELECT row_to_json(fc) FROM ( SELECT 'FeatureCollection' As type, array_to_json(array_agg(f)) As features FROM (SELECT 'Feature' As type, ST_AsGeoJSON(lg.geom)::json As geometry, row_to_json((id, name)) As properties FROM cambridge_coffee_shops As lg WHERE lg.name = \'" + name + "\') As f) As fc"; var client = new pg.Client(conString); client.connect(); var query = client.query(filter_query); query.on("row", function (row, result) { result.addRow(row); }); query.on("end", function (result) { var data = result.rows[0].row_to_json res.render('map', { title: "Express API", jsonData: data }); }); }; });
var connection = new pg.Client(config.pg) var adapter = puresql.adapters.pg(connection)
this.disconnectWatcher = new pg.Client({ host, port, user, password, database, ssl });
app.get('/', function (req, res) { var conString = "pg://admin:jackknife-approbation-sioux@postgres.hasura:5432/hasuradb"; var client = new pg.Client(conString); client.connect(); var query = client.query("SELECT * from test"); query.on("row", function (row, result) { result.addRow(row); }); query.on("end", function (result) { console.log(JSON.stringify(result.rows, null, " ")); client.end(); res.send("Data in table 'test':</br>" + JSON.stringify(result.rows, null, " ")); }); query.on("error",function(error) { console.log(error); res.send('Yo momma not so fat she crashed this query!'); }); });
/* GET the map page */ router.get('/map', function(req, res) { var client = new pg.Client(conString); client.connect(); var query = client.query(coffee_query); query.on("row", function (row, result) { result.addRow(row); }); query.on("end", function (result) { var data = result.rows[0].row_to_json res.render('map', { title: "Express API", jsonData: data }); }); });