本文整理汇总了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();
}