Extremely Popular
Go to Latest
method Transaction.prototype.commit
import { Transaction } from "https://dotland.deno.dev/x/postgres@v0.19.0/query/transaction.ts";

The commit method will make permanent all changes made to the database in the current transaction and end the current transaction

import { Client } from "https://deno.land/x/postgres/mod.ts";
const client = new Client();
const transaction = client.createTransaction("transaction");

await transaction.begin();
// Important operations
await transaction.commit(); // Will terminate the transaction and save all changes

The commit method allows you to specify a "chain" option, that allows you to both commit the current changes and start a new with the same transaction parameters in a single statement

import { Client } from "https://deno.land/x/postgres/mod.ts";
const client = new Client();
const transaction = client.createTransaction("transaction");

// Transaction operations I want to commit
await transaction.commit({ chain: true }); // All changes are saved, following statements will be executed inside a transaction
await transaction.queryArray`DELETE SOMETHING FROM SOMEWHERE`; // Still inside the transaction
await transaction.commit(); // The transaction finishes for good

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

Parameters

optional
options: { chain?: boolean; }