本文整理匯總了TypeScript中pg.Pool.end方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript Pool.end方法的具體用法?TypeScript Pool.end怎麽用?TypeScript Pool.end使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類pg.Pool
的用法示例。
在下文中一共展示了Pool.end方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: Pool
(async () => {
const pgPool = new Pool(pgConfig);
pgPool.on('error', err => {
// tslint:disable-next-line no-console
console.error('PostgreSQL client generated error: ', err.message);
});
const { getGraphQLSchema } = getPostgraphileSchemaBuilder(pgPool, schemas, postgraphileOptions);
await getGraphQLSchema();
if (!watchPg) {
await pgPool.end();
}
})().then(null, e => {
示例2: Pool
export const createPoolConnection = (conf: any): DBConnectionsPool => {
const pool: Pool = new Pool(conf);
return {
query(q) {
return pool.query(q);
},
connect() {
return pool.connect();
},
stop() {
return pool.end();
}
};
};
示例3: done
password: 'secret', //env var: PGPASSWORD
port: 5432, //env var: PGPORT
max: 10, // max number of clients in the pool
idleTimeoutMillis: 30000, // how long a client is allowed to remain idle before being closed
Promise,
};
var pool = new pg.Pool(config);
pool.connect((err, client, done) => {
if(err) {
return console.error('error fetching client from pool', err);
}
client.query('SELECT $1::int AS number', ['1'], (err, result) => {
done();
if(err) {
return console.error('error running query', err);
}
console.log(result.rows[0].number);
});
});
pool.on('error', (err, client) => {
console.error('idle client error', err.message, err.stack)
})
pool.end();
pool.end(() => {
console.log("pool is closed");
});
示例4: NOW
if (err) {
console.error('Error executing query', err.stack);
return;
}
console.log(result.rows[0].name);
});
pool.query('SELECT $1::text as name', ['brianc'])
.then((res) => console.log(res.rows[0].name))
.catch(err => console.error('Error executing query', err.stack));
pool.query({ text: 'SELECT $1::text as name' }, ['brianc'])
.then((res) => console.log(res.rows[0].name))
.catch(err => console.error('Error executing query', err.stack));
pool.end(() => {
console.log('pool has ended');
});
pool.end().then(() => console.log('pool has ended'));
(async () => {
const client = await pool.connect();
await client.query('SELECT NOW()');
client.release();
})();
// client constructor tests
// client config object tested above
let c = new Client(); // empty constructor allowed
c = new Client('connectionString'); // connection string allowed
示例5: QueryStream
import * as QueryStream from 'pg-query-stream';
import * as pg from 'pg';
const options: QueryStream.Options = {
highWaterMark: 1000,
batchSize: 100
};
const query = new QueryStream('SELECT * FROM generate_series(0, $1) num', [1000000], options);
const pool = new pg.Pool();
pool.connect((err, client, done) => {
const stream = client.query(query);
stream.on('end', () => {
client.end();
});
stream.on('data', (data: any) => {
console.log(data);
});
});
pool.end();
示例6: shutdown
export function shutdown(): Promise < any > {
return pool.end();
}