Skip to main content

Transaction

Struct Transaction 

Source
pub struct Transaction { /* private fields */ }
Expand description

Transaction represents a database transaction

Provides ACID guarantees for a series of database operations. Must be explicitly committed or rolled back.

Implementations§

Source§

impl Transaction

Source

pub fn append_audit_event(&mut self, event: AuditEvent) -> Result<[u8; 16]>

Append one audit event to this transaction. Embedded callers act as the bootstrap principal; server/procedural execution uses its authenticated execution context inside the executor host bridge.

Source

pub fn append_outbox_message( &mut self, message: OutboxMessage, ) -> Result<[u8; 16]>

Append one external side-effect intent to this business transaction.

Source§

impl Transaction

Source

pub fn execute_orm(&mut self, document: &IrDocument) -> OrmResult<i64>

Compile and execute command-like ORM IR inside this transaction.

Source

pub fn query_orm(&mut self, document: &IrDocument) -> OrmResult<Rows>

Compile and execute row-producing ORM IR inside this transaction.

Source

pub fn schema(&mut self) -> EmbeddedSchemaClient<'_>

Borrow this transaction for catalog operations without leaving it.

Source

pub fn entity(&mut self, table: impl Into<String>) -> OrmResult<DynamicEntity>

Source§

impl Transaction

Source

pub fn id(&self) -> i64

Get the transaction ID

Source

pub fn execute<P: Params>(&mut self, sql: &str, params: P) -> Result<i64>

Execute a SQL statement within the transaction

§Parameters

Parameters can be passed using:

  • Empty tuple () for no parameters
  • Tuple syntax (1, "Alice", 30) for multiple parameters
  • params! macro params![1, "Alice", 30]
§Examples
let mut tx = db.begin()?;
tx.execute("INSERT INTO users VALUES ($1, $2)", (1, "Alice"))?;
tx.execute("UPDATE accounts SET balance = balance - $1 WHERE user_id = $2", (100, 1))?;
tx.commit()?;
Source

pub fn execute_with_timeout<P: Params>( &mut self, sql: &str, params: P, timeout_ms: u64, ) -> Result<i64>

Execute a statement in this transaction with a cancellation deadline.

Source

pub fn execute_prepared<P: Params>( &mut self, statement: &Statement, params: P, ) -> Result<i64>

Execute a high-level prepared statement with parameters.

Avoids re-parsing SQL on every call — ideal for batch operations where the same statement is executed many times with different params.

Source

pub fn query_prepared<P: Params>( &mut self, statement: &Statement, params: P, ) -> Result<Rows>

Query using a pre-parsed statement with parameters.

Avoids re-parsing SQL on every call — ideal for batch read operations where the same query is executed many times with different params.

Source

pub fn query<P: Params>(&mut self, sql: &str, params: P) -> Result<Rows>

Execute a query within the transaction

§Examples
let mut tx = db.begin()?;
for row in tx.query("SELECT * FROM users WHERE age > $1", (18,))? {
    let row = row?;
    println!("{}", row.get::<String>("name")?);
}
tx.commit()?;
Source

pub fn query_with_timeout<P: Params>( &mut self, sql: &str, params: P, timeout_ms: u64, ) -> Result<Rows>

Query in this transaction with a cancellation deadline.

Source

pub fn query_one<T: FromValue, P: Params>( &mut self, sql: &str, params: P, ) -> Result<T>

Execute a query and return a single value

§Examples
let mut tx = db.begin()?;
let count: i64 = tx.query_one("SELECT COUNT(*) FROM users", ())?;
tx.commit()?;
Source

pub fn query_opt<T: FromValue, P: Params>( &mut self, sql: &str, params: P, ) -> Result<Option<T>>

Execute a query and return an optional single value

§Examples
let mut tx = db.begin()?;
let name: Option<String> = tx.query_opt("SELECT name FROM users WHERE id = $1", (999,))?;
tx.commit()?;
Source

pub fn execute_named(&mut self, sql: &str, params: NamedParams) -> Result<i64>

Execute a SQL statement with named parameters within the transaction

§Examples
use radixdb::named_params;

let mut tx = db.begin()?;
tx.execute_named(
    "INSERT INTO users VALUES (:id, :name)",
    named_params!{ id: 1, name: "Alice" }
)?;
tx.commit()?;
Source

pub fn query_named(&mut self, sql: &str, params: NamedParams) -> Result<Rows>

Execute a query with named parameters within the transaction

Source

pub fn execute_prepared_named( &mut self, statement: &Statement, params: NamedParams, ) -> Result<i64>

Execute a pre-parsed statement with named parameters.

Combines execute_prepared (skip parsing) with execute_named (named params).

Source

pub fn query_prepared_named( &mut self, statement: &Statement, params: NamedParams, ) -> Result<Rows>

Query using a pre-parsed statement with named parameters.

Combines query_prepared (skip parsing) with query_named (named params).

Source

pub fn commit(&mut self) -> Result<()>

Commit the transaction

All changes made within the transaction become permanent.

Source

pub fn rollback(&mut self) -> Result<()>

Roll back the transaction

All changes made within the transaction are discarded.

Source

pub fn is_active(&self) -> bool

True when the public handle still represents an active storage transaction and can be explicitly committed or rolled back.

Source

pub fn savepoint(&mut self, name: &str) -> Result<()>

Create or replace a transaction savepoint.

Names passed through the Rust API are exact strings. SQL identifier folding is applied by the SQL executor before it reaches this facade.

Source

pub fn rollback_to_savepoint(&mut self, name: &str) -> Result<()>

Roll back all changes made after name while retaining the target savepoint, so it can be used again or explicitly released.

Source

pub fn release_savepoint(&mut self, name: &str) -> Result<()>

Release a savepoint without rolling back its changes.

Trait Implementations§

Source§

impl Drop for Transaction

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl OrmGeneratedQuerySession for &mut Transaction

Source§

impl OrmGeneratedRecordSession for &mut Transaction

Source§

impl OrmRecordSession for &mut Transaction

Source§

impl OrmSession for &mut Transaction

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CompactArcDrop for T

Source§

unsafe fn drop_and_dealloc(ptr: *mut u8)

Drop the contained data and deallocate the header+data allocation. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V