function onSignal () { console.log('server is starting cleanup') return client.end().then(() => console.log('client has disconnected')) .catch(err => console.error('error during disconnection', err.stack)) }
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!") }) })
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(); } }); });
db.connect((err, client) => { if (err) throw err; console.log('Connected to database', db.database); db.query(` SELECT * FROM snippets ORDER BY id `, (err, result) => { if (err) throw err; console.log(result.rows); db.end(); }); });
function reset (cb) { var client = new Client({ database: 'postgres', user: process.env.PGUSER || 'postgres' }) client.connect(function (err) { if (err) throw err client.query('DROP DATABASE IF EXISTS test_elastic_apm', function (err) { if (err) throw err client.query('CREATE DATABASE test_elastic_apm', function (err) { if (err) throw err client.once('end', cb) client.end() }) }) }) }
query.on('end', () => {client.end();});
db.connect((err, client) => { db.query(` CREATE TABLE IF NOT EXISTS snippets ( id SERIAL, PRIMARY KEY(id), body text ); ` , (err, result) => { if (err) throw err; console.log('Created table "snippets"'); db.end(); }); });
export default function (config: any) { const client = new Client(config); return { query: (connectionString: any, query: any, params: any, callback: any) => { client.connect((connectError) => { if (connectError) { logger.error(`Error connecting to postgreSQL: ${connectError.stack}`); callback(connectError); } else { client.query(connectionString, (queryError: any, results: any) => { if (queryError) { throw Error(`Error executing postgreSQL query: ${queryError}`); } client.end(); callback(null, results); }); } }); }, }; }
client.query(table, async (err, res) => { if (err) { throw err } console.log('\n') console.log('Messages Table Created.') await client.end() })
db.connect((err, client) => { if (err) throw err; console.log('Connected to database', db.database); db.query(` CREATE TABLE IF NOT EXISTS snippets ( id SERIAL, PRIMARY KEY(id), body text ); `, (err, result) => { if (err) throw err; console.log('Created table "snippets"'); db.end(); }); });
db.connect((err, client) => { if (err) throw err; console.log('Connected to database', db.database); db.end(); });
function onSignal () { console.log('server is starting cleanup') return client.end().then(() => console.log('client has disconnected')) .catch(err => console.error('error during disconnection', err.stack)) }
db.connect((err, client) => { db.query(` CREATE TABLE IF NOT EXISTS snippets ( id SERIAL, PRIMARY KEY(id), body text ); ` , (err, result) => { if (err) throw err; console.log('Created table "snippets"'); db.end(); }); });
db.connect((err, client) => { db.query(` CREATE TABLE IF NOT EXISTS snippets ( id SERIAL, PRIMARY KEY(id), body text ); ` , (err, result) => { if (err) throw err; console.log('Created table "snippets"'); db.end(); }); });