import { postgres } from "https://deno.land/x/miranda@0.0.6/src/deps.ts";
const { Transaction } = postgres;
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