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
impl Transaction
Sourcepub fn append_audit_event(&mut self, event: AuditEvent) -> Result<[u8; 16]>
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.
Sourcepub fn append_outbox_message(
&mut self,
message: OutboxMessage,
) -> Result<[u8; 16]>
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
impl Transaction
Sourcepub fn execute_orm(&mut self, document: &IrDocument) -> OrmResult<i64>
pub fn execute_orm(&mut self, document: &IrDocument) -> OrmResult<i64>
Compile and execute command-like ORM IR inside this transaction.
Sourcepub fn query_orm(&mut self, document: &IrDocument) -> OrmResult<Rows>
pub fn query_orm(&mut self, document: &IrDocument) -> OrmResult<Rows>
Compile and execute row-producing ORM IR inside this transaction.
Sourcepub fn schema(&mut self) -> EmbeddedSchemaClient<'_>
pub fn schema(&mut self) -> EmbeddedSchemaClient<'_>
Borrow this transaction for catalog operations without leaving it.
pub fn entity(&mut self, table: impl Into<String>) -> OrmResult<DynamicEntity>
Source§impl Transaction
impl Transaction
Sourcepub fn execute<P: Params>(&mut self, sql: &str, params: P) -> Result<i64>
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!macroparams![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()?;Sourcepub fn execute_with_timeout<P: Params>(
&mut self,
sql: &str,
params: P,
timeout_ms: u64,
) -> Result<i64>
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.
Sourcepub fn execute_prepared<P: Params>(
&mut self,
statement: &Statement,
params: P,
) -> Result<i64>
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.
Sourcepub fn query_prepared<P: Params>(
&mut self,
statement: &Statement,
params: P,
) -> Result<Rows>
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.
Sourcepub fn query_with_timeout<P: Params>(
&mut self,
sql: &str,
params: P,
timeout_ms: u64,
) -> Result<Rows>
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.
Sourcepub fn query_opt<T: FromValue, P: Params>(
&mut self,
sql: &str,
params: P,
) -> Result<Option<T>>
pub fn query_opt<T: FromValue, P: Params>( &mut self, sql: &str, params: P, ) -> Result<Option<T>>
Sourcepub fn execute_named(&mut self, sql: &str, params: NamedParams) -> Result<i64>
pub fn execute_named(&mut self, sql: &str, params: NamedParams) -> Result<i64>
Sourcepub fn query_named(&mut self, sql: &str, params: NamedParams) -> Result<Rows>
pub fn query_named(&mut self, sql: &str, params: NamedParams) -> Result<Rows>
Execute a query with named parameters within the transaction
Sourcepub fn execute_prepared_named(
&mut self,
statement: &Statement,
params: NamedParams,
) -> Result<i64>
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).
Sourcepub fn query_prepared_named(
&mut self,
statement: &Statement,
params: NamedParams,
) -> Result<Rows>
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).
Sourcepub fn commit(&mut self) -> Result<()>
pub fn commit(&mut self) -> Result<()>
Commit the transaction
All changes made within the transaction become permanent.
Sourcepub fn rollback(&mut self) -> Result<()>
pub fn rollback(&mut self) -> Result<()>
Roll back the transaction
All changes made within the transaction are discarded.
Sourcepub fn is_active(&self) -> bool
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.
Sourcepub fn savepoint(&mut self, name: &str) -> Result<()>
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.
Sourcepub fn rollback_to_savepoint(&mut self, name: &str) -> Result<()>
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.
Sourcepub fn release_savepoint(&mut self, name: &str) -> Result<()>
pub fn release_savepoint(&mut self, name: &str) -> Result<()>
Release a savepoint without rolling back its changes.