TS
Size: a a a
TS
S
S
R
R
Y💜
V
АП
Е
В
В
ia
AO
async function transaction<T>(queries: { sql: string, params?: string[] }[]) {
const queryResult: QueryResult<T>[] = [];
const client = await pool.connect();
try {
await client.query('BEGIN');
for (const { sql: text, params } of queries) {
queryResult.push(await client.query({ text }, params));
}
await client.query('COMMIT');
} catch (e) {
await client.query('ROLLBACK');
throw e;
} finally {
client.release();
}
return queryResult.map(({ rows }) => rows);
}
S
S
AO
ia
S
ia