本文整理匯總了TypeScript中pg.Pool.query方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript Pool.query方法的具體用法?TypeScript Pool.query怎麽用?TypeScript Pool.query使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類pg.Pool
的用法示例。
在下文中一共展示了Pool.query方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: 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);
});
}
示例2: 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);
});
}
}
示例3: 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);
});
}
示例4: 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);
});
}
示例5: 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);
});
}
示例6: deleteTokensByKey
export async function deleteTokensByKey(userId: number, records: string[]) {
const sql = `DELETE FROM "Tokens"
WHERE "UserId"=$1
AND key = ANY ($2)`;
try {
await pool.query(sql, [userId, records]);
return true;
} catch (err) {
console.log(err);
return false;
}
}
示例7: deleteToken
export async function deleteToken(userId: number, key: string, value: string) {
const sql = `DELETE FROM "Tokens"
WHERE "UserId"=$1
AND key = $2
AND value = $3`;
try {
await pool.query(sql, [userId, key, value]);
return true;
} catch (err) {
console.log(err);
return false;
}
}
示例8: markMessagesRead
export async function markMessagesRead(userId: number, publicIds: string[]) {
const sql = `UPDATE "Messages"
SET unread=false
WHERE "UserId"=$1
AND "publicId" = ANY ($2)`;
try {
await pool.query(sql, [userId, publicIds]);
return true;
} catch (err) {
console.log(err);
return [];
}
}
示例9: 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();
}
};
};
示例10: getWebhookUrls
export async function getWebhookUrls(userId: number) {
const sql = `SELECT value
FROM "Tokens"
WHERE "UserId"=$1
AND key='webhook'`;
try {
const res = await pool.query(sql, [userId]);
return res.rows.map((row) => row.value);
} catch (err) {
console.log(err);
return [];
}
}