ouisync::db

Struct WriteTransaction

Source
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

Source

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.

Source

pub async fn commit_and_then<F, R>(self, f: F) -> Result<R, Error>
where F: FnOnce() -> R + Send + 'static, R: Send + 'static,

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:

  1. commit completes successfully and f is called
  2. commit completes with error and f is not called
  3. commit is cancelled but the transaction is still committed and f is not called
  4. commit is cancelled and the transaction rolls back and f is 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:

  1. commit completes successfully and f is called
  2. commit completes with error and f is called
  3. commit is cancelled but the transaction is still committed and f is called
  4. commit is cancelled and the transaction rolls back and f is 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

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Deref for WriteTransaction

Source§

type Target = ReadTransaction

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl DerefMut for WriteTransaction

Source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
Source§

impl<'t> Executor<'t> for &'t mut WriteTransaction

Source§

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,

Execute multiple queries and return the generated results as a stream from each query, in a stream.
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,

Execute the query and returns at most one row.
Source§

fn prepare_with<'e, 'q: 'e>( self, sql: &'q str, parameters: &'e [SqliteTypeInfo], ) -> BoxFuture<'e, Result<SqliteStatement<'q>, Error>>
where 't: 'e,

Prepare the SQL query, with parameter type information, to inspect the type information about its parameters and results. Read more
§

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>,

Execute the query and return the total number of rows affected.
§

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>,

Execute multiple queries and return the rows affected from each query, in a stream.
§

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>,

Execute the query and return the generated results as a stream.
§

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>,

Execute the query and return all the generated results, collected into a Vec.
§

fn fetch_one<'e, 'q, E>( self, query: E, ) -> Pin<Box<dyn Future<Output = Result<<Self::Database as Database>::Row, Error>> + Send + 'e>>
where 'q: 'e, 'c: 'e, E: 'q + Execute<'q, Self::Database>,

Execute the query and returns exactly one row.
§

fn prepare<'e, 'q>( self, query: &'q str, ) -> Pin<Box<dyn Future<Output = Result<<Self::Database as HasStatement<'q>>::Statement, Error>> + Send + 'e>>
where 'q: 'e, 'c: 'e,

Prepare the SQL query to inspect the type information of its parameters and results. Read more

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
§

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

§

fn vzip(self) -> V

§

impl<T> Value for T
where T: Debug + Any + Send + 'static,

§

fn as_any(&self) -> &(dyn Any + 'static)

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<T> ErasedDestructor for T
where T: 'static,

§

impl<T> MaybeSendSync for T