beforeAll(async () => { const pool = new pg.Pool(adminConnection) const sq = sqorn({ pg, pool }) await sq.sql`drop database if exists ${sq.raw(db_name)}` await sq.sql`create database ${sq.raw(db_name)}` await sq.end() })
const createTestDatabase = async () => { // create test database let sq = sqorn({ pg, pool: new pg.Pool(adminConnection) }) await sq.sql`drop database if exists ${sq.raw(db_name)}` await sq.sql`create database ${sq.raw(db_name)}` await sq.end() // populate test database sq = sqorn({ pg, pool: new pg.Pool(appConnection) }) await sq.sql`create table person ( id serial primary key, first_name text, last_name text )` await sq`person`.insert( { firstName: 'Jo', lastName: 'Schmo' }, { firstName: 'Bo', lastName: 'Mo' } ) await sq.end() }
describe('thenable', async () => { test('default = true', async () => { const sq = sqorn({ pg, pool: new pg.Pool(appConnection) }) try { expect(await sq`person`({ firstName: 'Jo' })`last_name`).toEqual([ const sq = sqorn({ pg, pool: new pg.Pool(appConnection), thenable: true }) const sq = sqorn({ pg, pool: new pg.Pool(appConnection), thenable: false })
describe('mapInputKeys', () => { test('default snake_case 1', async () => { const sq = sqorn({ pg, pool: new pg.Pool(appConnection) }) try { expect( const sq = sqorn({ pg, pool: new pg.Pool(appConnection) }) try { expect( const sq = sqorn({ pg, pool: new pg.Pool(appConnection), mapInputKeys: key => key }) const sq = sqorn({ pg, pool: new pg.Pool(appConnection), mapInputKeys: key => key.toUpperCase() })
describe('mapOutputKeys', () => { test('default camelCase', async () => { const sq = sqorn({ pg, pool: new pg.Pool(appConnection) }) try { expect( const sq = sqorn({ pg, pool: new pg.Pool(appConnection) }) try { expect( const sq = sqorn({ pg, pool: new pg.Pool(appConnection) }) try { expect(await sq.from`person`.return`first_name`).toEqual([ const sq = sqorn({ pg, pool: new pg.Pool(appConnection), mapOutputKeys: key => key }) const sq = sqorn({ pg, pool: new pg.Pool(appConnection), mapOutputKeys: key => key.toUpperCase() })
pgpool.on('error', (e, c) => { console.log('pgpool error: ' + e); pgpool.end(); setTimeout(function () { pgpool = new pg.Pool(db_config); }, 100); })
async open () { this.pool = new pg.Pool(this.config) this.pool.on('error', error => this.emit('error', error)) this.opened = true }
// Open PostgresProvider // options - <Object>, to be passed to pg // Returns: <Promise> async open(options) { await super.open(options); this.pool = new pg.Pool(options); this.active = true; return this; }
const waitForPostgres = async function ({ url }) { if (!url) { throw new Error('Url is missing.'); } const { host, port, user, password, database } = new DsnParser(url).getParts(); const pool = new pg.Pool({ host, port, user, password, database }); await retry(async () => { const connection = await pool.connect(); connection.release(); }); await pool.end(); }
function createPool (cb) { setup(function () { var connector if (semver.satisfies(pgVersion, '<6.0.0')) { queryable = pg connector = function connector (cb) { return pg.connect({ database: 'test_elastic_apm', user: process.env.PGUSER || 'postgres' }, cb) } } else { var pool = new pg.Pool({ database: 'test_elastic_apm', user: process.env.PGUSER || 'postgres' }) queryable = pool connector = function connector (cb) { return pool.connect(cb) } } cb(connector) }) }
(function(config){ const pool = new pg.Pool(config); // https://www.npmjs.com/package/pg-pool return { query : function(sql, errorMessage = "default message") { return pool.connect().then(client => { return client.query(sql).then(res => { client.release(); return res; }) .catch(err => { try { client.release(); } catch(err) { console.error("error when client was to be released. Maybe the client has already been released.")} console.error(errorMessage + " = " + err); }); }, err => { console.error("error occuren when try to connect = ", err); // TODO: Handle common message }); } } })(CONFIG)
init() { if (!this.pool) { this.pool = new pg.Pool(config.postgresql); } }
init() { if (!this.pool) { this.pool = new pg.Pool(config); } }