deno.land / x / pasta@0.0.6 / src / transaction.ts

transaction.ts
نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// Automatically generated by PASTAimport postgres from "https://deno.land/x/postgresjs@v3.2.4/mod.js";import type { SqlBuilder } from "./sql-builder.ts";
function connection(uri: string) { const sql = postgres(uri); return sql;}
async function transaction(statement: SqlBuilder) { const uri = Deno.env.get("DATABASE_URL"); if (!uri) { throw new Error("Please set DATABASE_URL to use database access functions"); } const sql = postgres(uri); const r = await sql.unsafe(statement.toSql()); await sql.end({ timeout: 5 }); return r;}
async function transactionReturning(statement: SqlBuilder) { const r = await transaction(statement); if (r.length === 0) { throw new Error( "Statement" + statement.toSql() + " did not return any rows", ); } return r;}
const db = { transaction, transactionReturning,};
export { connection, db, transaction, transactionReturning };
pasta

Version Info

Tagged at
a year ago