Skip to main content

Module transaction

Module transaction 

Source
Expand description

Transaction API

Provides ACID transaction support with the same ergonomic API as Database.

§Examples

use radixdb_api::Database;

let db = Database::open("memory://")?;
db.execute("CREATE TABLE accounts (id INTEGER, balance INTEGER)", ())?;
db.execute("INSERT INTO accounts VALUES ($1, $2), ($3, $4)", (1, 1000, 2, 500))?;

// Transfer money atomically
let mut tx = db.begin()?;
tx.execute("UPDATE accounts SET balance = balance - $1 WHERE id = $2", (100, 1))?;
tx.execute("UPDATE accounts SET balance = balance + $1 WHERE id = $2", (100, 2))?;
tx.commit()?;

Structs§

Transaction
Transaction represents a database transaction