pub struct WriteTransaction { /* private fields */ }Expand description
Transaction that allows both reading and writing.
At most one task can hold a write transaction at any time. Any other tasks are blocked on
calling begin_write until the task that currently holds it is done with it (commits it or
rolls it back). Performing read-only operations concurrently while a write transaction is in
use is still allowed. Those operations will not see the writes performed via the write
transaction until that transaction is committed however.
Implementations§
Source§impl WriteTransaction
impl WriteTransaction
Sourcepub async fn commit(self) -> Result<(), Error>
pub async fn commit(self) -> Result<(), Error>
Commits the transaction.
§Cancel safety
If the future returned by this function is cancelled before completion, the transaction is guaranteed to be either committed or rolled back but there is no way to tell in advance which of the two operations happens.
Sourcepub async fn commit_and_then<F, R>(self, f: F) -> Result<R, Error>
pub async fn commit_and_then<F, R>(self, f: F) -> Result<R, Error>
Commits the transaction and if (and only if) the commit completes successfully, runs the given closure.
§Atomicity
If the commit succeeds, the closure is guaranteed to complete before another write transaction begins.
§Cancel safety
The commits completes and if it succeeds the closure gets called. This is guaranteed to happen even if the future returned from this function is cancelled before completion.
§Insufficient alternatives
§Calling commit().await? and then calling f()
This is not enough because it has these possible outcomes depending on whether and when cancellation happened:
commitcompletes successfully andfis calledcommitcompletes with error andfis not calledcommitis cancelled but the transaction is still committed andfis not calledcommitis cancelled and the transaction rolls back andfis not called
Number 3 is typically not desirable.
§Calling f using a RAII guard
This is still not enough because it has the following possible outcomes:
commitcompletes successfully andfis calledcommitcompletes with error andfis calledcommitis cancelled but the transaction is still committed andfis calledcommitis cancelled and the transaction rolls back andfis called
Numbers 2 and 4 are not desirable. Number 2 can be handled by explicitly handling the error case and disabling the guard but there is nothing to do about number 4.
Trait Implementations§
Source§impl Debug for WriteTransaction
impl Debug for WriteTransaction
Source§impl Deref for WriteTransaction
impl Deref for WriteTransaction
Source§impl DerefMut for WriteTransaction
impl DerefMut for WriteTransaction
Source§impl<'t> Executor<'t> for &'t mut WriteTransaction
impl<'t> Executor<'t> for &'t mut WriteTransaction
type Database = Sqlite
Source§fn fetch_many<'e, 'q: 'e, E>(
self,
query: E,
) -> BoxStream<'e, Result<Either<SqliteQueryResult, SqliteRow>, Error>>where
E: Execute<'q, Sqlite> + 'q,
't: 'e,
fn fetch_many<'e, 'q: 'e, E>(
self,
query: E,
) -> BoxStream<'e, Result<Either<SqliteQueryResult, SqliteRow>, Error>>where
E: Execute<'q, Sqlite> + 'q,
't: 'e,
Source§fn fetch_optional<'e, 'q: 'e, E>(
self,
query: E,
) -> BoxFuture<'e, Result<Option<SqliteRow>, Error>>where
E: Execute<'q, Sqlite> + 'q,
't: 'e,
fn fetch_optional<'e, 'q: 'e, E>(
self,
query: E,
) -> BoxFuture<'e, Result<Option<SqliteRow>, Error>>where
E: Execute<'q, Sqlite> + 'q,
't: 'e,
Source§fn prepare_with<'e, 'q: 'e>(
self,
sql: &'q str,
parameters: &'e [SqliteTypeInfo],
) -> BoxFuture<'e, Result<SqliteStatement<'q>, Error>>where
't: 'e,
fn prepare_with<'e, 'q: 'e>(
self,
sql: &'q str,
parameters: &'e [SqliteTypeInfo],
) -> BoxFuture<'e, Result<SqliteStatement<'q>, Error>>where
't: 'e,
§fn execute<'e, 'q, E>(
self,
query: E,
) -> Pin<Box<dyn Future<Output = Result<<Self::Database as Database>::QueryResult, Error>> + Send + 'e>>where
'q: 'e,
'c: 'e,
E: 'q + Execute<'q, Self::Database>,
fn execute<'e, 'q, E>(
self,
query: E,
) -> Pin<Box<dyn Future<Output = Result<<Self::Database as Database>::QueryResult, Error>> + Send + 'e>>where
'q: 'e,
'c: 'e,
E: 'q + Execute<'q, Self::Database>,
§fn execute_many<'e, 'q, E>(
self,
query: E,
) -> Pin<Box<dyn Stream<Item = Result<<Self::Database as Database>::QueryResult, Error>> + Send + 'e>>where
'q: 'e,
'c: 'e,
E: 'q + Execute<'q, Self::Database>,
fn execute_many<'e, 'q, E>(
self,
query: E,
) -> Pin<Box<dyn Stream<Item = Result<<Self::Database as Database>::QueryResult, Error>> + Send + 'e>>where
'q: 'e,
'c: 'e,
E: 'q + Execute<'q, Self::Database>,
§fn fetch<'e, 'q, E>(
self,
query: E,
) -> Pin<Box<dyn Stream<Item = Result<<Self::Database as Database>::Row, Error>> + Send + 'e>>where
'q: 'e,
'c: 'e,
E: 'q + Execute<'q, Self::Database>,
fn fetch<'e, 'q, E>(
self,
query: E,
) -> Pin<Box<dyn Stream<Item = Result<<Self::Database as Database>::Row, Error>> + Send + 'e>>where
'q: 'e,
'c: 'e,
E: 'q + Execute<'q, Self::Database>,
§fn fetch_all<'e, 'q, E>(
self,
query: E,
) -> Pin<Box<dyn Future<Output = Result<Vec<<Self::Database as Database>::Row>, Error>> + Send + 'e>>where
'q: 'e,
'c: 'e,
E: 'q + Execute<'q, Self::Database>,
fn fetch_all<'e, 'q, E>(
self,
query: E,
) -> Pin<Box<dyn Future<Output = Result<Vec<<Self::Database as Database>::Row>, Error>> + Send + 'e>>where
'q: 'e,
'c: 'e,
E: 'q + Execute<'q, Self::Database>,
Vec.Auto Trait Implementations§
impl Freeze for WriteTransaction
impl !RefUnwindSafe for WriteTransaction
impl Send for WriteTransaction
impl Sync for WriteTransaction
impl Unpin for WriteTransaction
impl !UnwindSafe for WriteTransaction
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
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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