pub struct Transaction<'db> { /* private fields */ }Expand description
Explicit transaction over the in-memory graph.
The implementation is conservative: read-only transactions hold a database read lock, and read-write transactions hold the database write lock. Read-write transactions lazily create a cloned staging graph on the first mutating statement, then either swap that graph into place on commit or drop it on rollback. Explicit mutating statements capture a graph + WAL-buffer savepoint so a failed or dropped streaming statement only rolls back its own effects, not the transaction as a whole.
When a WAL is attached, mutation events fire into a tx-local buffer rather than the durable log. The buffer is replayed into the WAL exactly once at commit, so recovery never observes partial / aborted / dropped statements.
Implementations§
Source§impl<'db> Transaction<'db>
impl<'db> Transaction<'db>
Sourcepub fn mode(&self) -> TransactionMode
pub fn mode(&self) -> TransactionMode
Transaction mode chosen at begin time.
Sourcepub fn execute(
&mut self,
query: &str,
options: Option<ExecuteOptions>,
) -> Result<QueryResult, LoraError>
pub fn execute( &mut self, query: &str, options: Option<ExecuteOptions>, ) -> Result<QueryResult, LoraError>
Execute a query inside the transaction and return a materialized
QueryResult.
Sourcepub fn execute_with_timeout(
&mut self,
query: &str,
options: Option<ExecuteOptions>,
timeout: Duration,
) -> Result<QueryResult, LoraError>
pub fn execute_with_timeout( &mut self, query: &str, options: Option<ExecuteOptions>, timeout: Duration, ) -> Result<QueryResult, LoraError>
Execute a query inside the transaction with a cooperative deadline.
Sourcepub fn execute_with_params(
&mut self,
query: &str,
options: Option<ExecuteOptions>,
params: BTreeMap<String, LoraValue>,
) -> Result<QueryResult, LoraError>
pub fn execute_with_params( &mut self, query: &str, options: Option<ExecuteOptions>, params: BTreeMap<String, LoraValue>, ) -> Result<QueryResult, LoraError>
Execute a parameterised query inside the transaction.
Sourcepub fn execute_with_params_timeout(
&mut self,
query: &str,
options: Option<ExecuteOptions>,
params: BTreeMap<String, LoraValue>,
timeout: Duration,
) -> Result<QueryResult, LoraError>
pub fn execute_with_params_timeout( &mut self, query: &str, options: Option<ExecuteOptions>, params: BTreeMap<String, LoraValue>, timeout: Duration, ) -> Result<QueryResult, LoraError>
Execute a parameterised query inside the transaction with a cooperative deadline.
Sourcepub fn execute_with_params_deadline(
&mut self,
query: &str,
options: Option<ExecuteOptions>,
params: BTreeMap<String, LoraValue>,
deadline: Instant,
) -> Result<QueryResult, LoraError>
pub fn execute_with_params_deadline( &mut self, query: &str, options: Option<ExecuteOptions>, params: BTreeMap<String, LoraValue>, deadline: Instant, ) -> Result<QueryResult, LoraError>
Execute a parameterised query inside the transaction that stops at an
absolute deadline (see crate::Database::execute_with_params_deadline).
Several statements can share one deadline to bound the whole
transaction.
Sourcepub fn execute_rows(&mut self, query: &str) -> Result<Vec<Row>, LoraError>
pub fn execute_rows(&mut self, query: &str) -> Result<Vec<Row>, LoraError>
Execute a query inside the transaction and return hydrated rows before final result-format projection.
Sourcepub fn execute_rows_with_params(
&mut self,
query: &str,
params: BTreeMap<String, LoraValue>,
) -> Result<Vec<Row>, LoraError>
pub fn execute_rows_with_params( &mut self, query: &str, params: BTreeMap<String, LoraValue>, ) -> Result<Vec<Row>, LoraError>
Execute a parameterised query inside the transaction and return hydrated rows before final result-format projection.
Sourcepub fn explain(
&self,
query: &str,
_params: Option<BTreeMap<String, LoraValue>>,
) -> Result<QueryPlan, LoraError>
pub fn explain( &self, query: &str, _params: Option<BTreeMap<String, LoraValue>>, ) -> Result<QueryPlan, LoraError>
Compile query against the transaction’s view of the graph and
return the plan that would run. Never executes the query, so
running explain on a mutating statement leaves the transaction’s
staged graph untouched.
Sourcepub fn profile(
&mut self,
query: &str,
params: Option<BTreeMap<String, LoraValue>>,
) -> Result<QueryProfile, LoraError>
pub fn profile( &mut self, query: &str, params: Option<BTreeMap<String, LoraValue>>, ) -> Result<QueryProfile, LoraError>
Execute query inside the transaction and return the plan plus
runtime metrics.
PROFILE executes the query for real. Mutating statements
affect the transaction’s staged graph and are persisted at the
usual commit point. Use Transaction::explain to inspect a
plan without running it.
Sourcepub fn stream(&mut self, query: &str) -> Result<QueryStream<'static>, LoraError>
pub fn stream(&mut self, query: &str) -> Result<QueryStream<'static>, LoraError>
Execute a query inside the transaction and return an owning row stream.
Sourcepub fn stream_with_params(
&mut self,
query: &str,
params: BTreeMap<String, LoraValue>,
) -> Result<QueryStream<'static>, LoraError>
pub fn stream_with_params( &mut self, query: &str, params: BTreeMap<String, LoraValue>, ) -> Result<QueryStream<'static>, LoraError>
Execute a parameterised query inside the transaction and return an owning row stream.
Sourcepub fn commit(self) -> Result<(), LoraError>
pub fn commit(self) -> Result<(), LoraError>
Commit the transaction and publish staged changes.
When WAL is attached the buffered tx-local mutation log is replayed into the durable WAL as a single committed transaction; recovery therefore observes either every write in this transaction or none.
Trait Implementations§
Source§impl Drop for Transaction<'_>
impl Drop for Transaction<'_>
Auto Trait Implementations§
impl<'db> !RefUnwindSafe for Transaction<'db>
impl<'db> !Send for Transaction<'db>
impl<'db> !UnwindSafe for Transaction<'db>
impl<'db> Freeze for Transaction<'db>
impl<'db> Sync for Transaction<'db>
impl<'db> Unpin for Transaction<'db>
impl<'db> UnsafeUnpin for Transaction<'db>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more