Skip to main content
Module

x/postgres/mod.ts>Transaction#begin

PostgreSQL driver for Deno
Extremely Popular
Go to Latest
method Transaction.prototype.begin
import { Transaction } from "https://deno.land/x/postgres@v0.17.0/mod.ts";

The begin method will officially begin the transaction, and it must be called before any query or transaction operation is executed in order to lock the session

import { Client } from "../client.ts";

const client = new Client();
const transaction = client.createTransaction("transaction_name");

await transaction.begin(); // Session is locked, transaction operations are now safe
// Important operations
await transaction.commit(); // Session is unlocked, external operations can now take place

https://www.postgresql.org/docs/14/sql-begin.html