本文整理汇总了TypeScript中pg.Pool类的典型用法代码示例。如果您正苦于以下问题:TypeScript Pool类的具体用法?TypeScript Pool怎么用?TypeScript Pool使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Pool类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: Date
(async () => {
const client = await pool.connect();
try {
for (const message of messages) {
await client.query(
sql,
[
message.body,
message.expiresAt,
message.group,
message.localId,
message.publicId,
message.source,
message.title,
message.url,
new Date(),
userId,
message.badge,
],
);
}
await client.query('COMMIT');
} catch (e) {
await client.query('ROLLBACK');
throw e;
} finally {
client.release();
}
})().catch((e) => console.error(e.stack));
示例4: checkExchangeSimple
export function checkExchangeSimple(exchange: Exchange, exchange_details: string[]): Promise < any > {
return pool.query(
// tslint:disable-next-line:max-line-length
"INSERT INTO exchanges (exchange_name, pairs) VALUES ($1, $2) ON CONFLICT (exchange_name) DO UPDATE SET exchange_name = $1, pairs = $2", [exchange.name, exchange_details]
).catch(e => {
logger.logError("checkExchange query", e);
});
}
示例5: checkAsset
export function checkAsset(ticker: string, asset_details: string[], exchange: string): Promise < any > {
ticker = getTicker(ticker, exchange.toLowerCase());
if (assets[ticker]) {
// tslint:disable-next-line:max-line-length
return pool.query("INSERT INTO assets (asset_ticker, asset_name, asset_website, asset_total_supply, exchanges) VALUES ($1, $2, $3, $4, $5) ON CONFLICT (asset_ticker) DO UPDATE SET asset_name = $2, asset_website=$3, asset_total_supply=$4, exchanges=$5", [ticker, assets[ticker].name, assets[ticker].website_url, assets[ticker].total_supply, asset_details])
.catch(e => {
logger.logError("checkAsset query", e);
});
} else {
// tslint:disable-next-line:max-line-length
return pool.query("INSERT INTO assets (asset_ticker, exchanges) VALUES ($1, $2) ON CONFLICT (asset_ticker) DO UPDATE SET exchanges = $2", [ticker, asset_details])
.catch(e => {
logger.logError("checkAsset query", e);
});
}
}
示例6: checkExchangePairSimple
export function checkExchangePairSimple(base: string, quote: string, exchange: string): Promise < any > {
base = getTicker(base, exchange.toLowerCase());
quote = getTicker(quote, exchange.toLowerCase());
// tslint:disable-next-line:max-line-length
return pool.query("INSERT INTO exchange_pairs (exchange_id, pair_id) SELECT (SELECT exchange_id FROM exchanges WHERE exchange_name = $1), (SELECT p.pair_id FROM pairs p WHERE p.base_id = (SELECT asset_id FROM assets WHERE asset_ticker = $2) AND p.quote_id = (SELECT asset_id FROM assets WHERE asset_ticker = $3)) ON CONFLICT (exchange_id, pair_id) DO NOTHING", [exchange, base, quote])
.catch(e => {
logger.logError("checkExchangePair query base: " + base + " quote: " + quote, e);
});
}
示例7: checkExchangePair
export function checkExchangePair(base: string, quote: string, precision: number, active: boolean, exchange: string): Promise < any > {
base = getTicker(base, exchange.toLowerCase());
quote = getTicker(quote, exchange.toLowerCase());
// tslint:disable-next-line:max-line-length
return pool.query("INSERT INTO exchange_pairs (exchange_id, pair_id, price_precision, active) SELECT (SELECT exchange_id FROM exchanges WHERE exchange_name = $1), (SELECT p.pair_id FROM pairs p WHERE p.base_id = (SELECT asset_id FROM assets WHERE asset_ticker = $2) AND p.quote_id = (SELECT asset_id FROM assets WHERE asset_ticker = $3)), $4, $5 ON CONFLICT (exchange_id, pair_id) DO UPDATE SET price_precision = $4, active = $5", [exchange, base, quote, precision, active])
.catch(e => {
logger.logError("checkExchangePair query base: " + base + " quote: " + quote, e);
});
}
示例8: checkPair
export function checkPair(base: string, quote: string, pair_details: string[], exchange: string): Promise < any > {
base = getTicker(base, exchange.toLowerCase());
quote = getTicker(quote, exchange.toLowerCase());
// tslint:disable-next-line:max-line-length
return pool.query("INSERT INTO pairs (base_id, quote_id, exchanges, base, quote) SELECT (SELECT asset_id FROM assets WHERE asset_ticker = $1), (SELECT asset_id FROM assets WHERE asset_ticker = $2), $3, $1, $2 ON CONFLICT (base_id, quote_id) DO UPDATE SET exchanges = $3, base = $1, quote = $2", [base, quote, pair_details])
.catch(e => {
logger.logError("checkPair query", e);
});
}
示例9:
app.post('/event-types', (req, res) => {
pool.connect((connectionError, client, releaseClient) => {
if (connectionError) return console.error('Error fetching client from pool', connectionError);
client.query(`SELECT event_type.id as key, event_type.title as value, event_type.body FROM event_type WHERE event_type.title LIKE '%${req.body.query}%';`, (queryError, result) => {
if (queryError) return console.error('Error querying database', queryError);
res.send(result.rows);
releaseClient();
});
});
});