Skip to main content
Module

x/postgres/mod.ts>Transaction#commit

PostgreSQL driver for Deno
Extremely Popular
Go to Latest
method Transaction.prototype.commit
import { Transaction } from "https://deno.land/x/postgres@v0.17.0/mod.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 "../client.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 "../client.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; }