pub struct TransactionMut<'a, S> { /* private fields */ }
Expand description
Same as Transaction, but allows inserting new rows.
TransactionMut always uses the latest version of the database, with the effects of all previous TransactionMuts applied.
To make mutations to the database permanent you need to use TransactionMut::commit. This is to make sure that if a function panics while holding a mutable transaction, it will roll back those changes.
Implementations§
Source§impl<'t, S> TransactionMut<'t, S>
impl<'t, S> TransactionMut<'t, S>
Sourcepub fn try_insert<T: Table>(
&mut self,
val: impl Writable<T = T>,
) -> Option<TableRow<'t, T>>
pub fn try_insert<T: Table>( &mut self, val: impl Writable<T = T>, ) -> Option<TableRow<'t, T>>
Try inserting a value into the database.
Returns a reference to the new inserted value or None
if there is a conflict.
Conflicts can occur due too unique constraints in the schema.
The method takes a mutable reference so that it can not be interleaved with a multi row query.
Sourcepub fn commit(self)
pub fn commit(self)
Make the changes made in this TransactionMut permanent.
If the TransactionMut is dropped without calling this function, then the changes are rolled back.
Methods from Deref<Target = Transaction<'a, S>>§
Sourcepub fn query<F, R>(&self, f: F) -> R
pub fn query<F, R>(&self, f: F) -> R
Execute a query with multiple results.
Please take a look at the documentation of Query for how to use it.
Sourcepub fn query_one<O>(&self, val: impl Dummy<'static, 't, S, Out = O>) -> Owhere
S: 'static,
pub fn query_one<O>(&self, val: impl Dummy<'static, 't, S, Out = O>) -> Owhere
S: 'static,
Retrieve a single result from the database.
Instead of using Self::query_one in a loop, it is better to call Self::query and return all results at once.