Closed netux closed 3 years ago
Utility function to create a temporary PoolClient connection which is always released once the argument function ends.
import { PoolClient } from 'pg'; import * as database from 'database.ts'; const result = await database.withConnection((connection: PoolClient) => connection.query('SELECT * FROM my_table')); async function getPrefix(connection: PoolClient, guildID: string) { const { rows } = await connection.query('SELECT prefix FROM config WHERE guild_id = $1', [guildID]); return rows.length > 0 ? rows[0].prefix : DEFAULT_PREFIX; } const prefix = await database.withConnection(getPrefix, guildID);
Utility function to create a temporary PoolClient connection which is always released once the argument function ends.
Usage: