Skip to main content

Transaction

Struct Transaction 

Source
pub struct Transaction { /* private fields */ }
Expand description

This is a guard over an in-flight transaction.

In a perfect world we’d be able to use [rusqlite::Transaction], but that type is intentionally !Send + !Sync, which prevents us from being able to keep a long-lived transaction around.

Dropping the transaction without committing performs an implicit rollback.

This type is always wrapped in a UniqueArc, which keeps things efficient, at the cost of prohibiting Clone. In case you need to share this around, there are weak references available via UniqueArc::downgrade. Alternately, wrap the entire thing in an Arc<Mutex<Option<UniqueArc<Self>>>> or similar. Just be aware that you’ll need to take the unique arc out in order to commit.

Implementations§

Source§

impl Transaction

Source

pub fn conn(&self) -> CryptoKeystoreResult<TransactionConnection>

Guard over this transaction’s connection.

Errors if SQLite has already rolled this transaction back under us.

Source§

impl Transaction

Source

pub async fn with_savepoint<T, E>( &self, savepoint_name: &str, operation: impl AsyncFnOnce() -> Result<T, E>, map_err: impl Fn(&'static str) -> Box<dyn FnOnce(CryptoKeystoreError) -> E>, ) -> Result<T, E>

Do an operation within the context of a savepoint.

https://sqlite.org/lang_savepoint.html

A savepoint is like a transaction, but has a name and can be nested. This allows for more fine-grained control over what makes it into the history, or not.

The operation produces an arbitrary result which is forwarded unmodified to the output of this method. If that result is ok, the savepoint is released (i.e. committed). If that result is an error, the savepoint is rolled back.

Error-mapping is the most complicated part of this. When an error is produced in the course of this method, we run the map_err function with a static context string describing what was happening. That function must return a second function which transforms a CryptoKeystoreError into an instance of E.

Trait Implementations§

Source§

impl Drop for Transaction

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl FetchFromDatabase for Transaction

Source§

fn get<'life0, 'life1, 'async_trait, E>( &'life0 self, id: &'life1 E::PrimaryKey, ) -> Pin<Box<dyn Future<Output = CryptoKeystoreResult<Option<Arc<E>>>> + Send + 'async_trait>>
where E: 'static + Entity + Clone + Send + Sync + 'async_trait, Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Get an instance of E from the database by its primary key.
Source§

fn get_borrowed<'life0, 'life1, 'async_trait, E>( &'life0 self, id: <E as BorrowPrimaryKey>::BorrowedPrimaryKey<'life1>, ) -> Pin<Box<dyn Future<Output = CryptoKeystoreResult<Option<Arc<E>>>> + Send + 'async_trait>>
where E: 'static + EntityGetBorrowed + Clone + Send + Sync + 'async_trait, Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Get an instance of E from the database by the borrowed form of its primary key.
Source§

fn count<'life0, 'async_trait, E>( &'life0 self, ) -> Pin<Box<dyn Future<Output = CryptoKeystoreResult<u32>> + Send + 'async_trait>>
where E: 'static + Entity + Clone + Send + Sync + 'async_trait, Self: 'async_trait, 'life0: 'async_trait,

Count the number of Es in the database.
Source§

fn load_all<'life0, 'async_trait, E>( &'life0 self, ) -> Pin<Box<dyn Future<Output = CryptoKeystoreResult<Vec<Arc<E>>>> + Send + 'async_trait>>
where E: 'static + Entity + Clone + Send + Sync + 'async_trait, Self: 'async_trait, 'life0: 'async_trait,

Load all Es from the database.
Source§

fn search<'life0, 'life1, 'async_trait, E, SearchKey>( &'life0 self, search_key: &'life1 SearchKey, ) -> Pin<Box<dyn Future<Output = CryptoKeystoreResult<Vec<Arc<E>>>> + Send + 'async_trait>>
where E: 'static + Entity + SearchableEntity<SearchKey> + Clone + Send + Sync + 'async_trait, SearchKey: Send + Sync + ?Sized + 'async_trait, Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Search for relevant instances of E given a search key.
Source§

fn get_unique<'a, 'life0, 'async_trait, U>( &'life0 self, ) -> Pin<Box<dyn Future<Output = CryptoKeystoreResult<Option<Arc<U>>>> + Send + 'async_trait>>
where U: 'static + UniqueEntityExt + Entity + Clone + Send + Sync + 'async_trait, Self: 'async_trait, 'a: 'async_trait, 'life0: 'async_trait,

Get the requested unique entity from the database.
Source§

fn exists<'a, 'life0, 'async_trait, U>( &'life0 self, ) -> Pin<Box<dyn Future<Output = CryptoKeystoreResult<bool>> + Send + 'async_trait>>
where U: 'static + UniqueEntityExt + Entity + Clone + Send + Sync + 'async_trait, Self: 'async_trait, 'a: 'async_trait, 'life0: 'async_trait,

Determine whether a unique entity is present in the database.
Source§

impl<'a> From<&'a Transaction> for Transactionlike<'a>

Source§

fn from(value: &'a Transaction) -> Self

Converts to this type from the input type.
Source§

impl OpenMlsKeyStore for Transaction

Source§

type Error = CryptoKeystoreError

The error type returned by the [OpenMlsKeyStore].
Source§

fn store<'life0, 'life1, 'life2, 'async_trait, V>( &'life0 self, id: &'life1 [u8], value: &'life2 V, ) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>>
where Self: Sized + 'async_trait, V: 'async_trait + MlsEntity + Sync, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Store a value v that implements the [MlsEntity] trait for serialization for ID k. Read more
Source§

fn read<'life0, 'life1, 'async_trait, V>( &'life0 self, id: &'life1 [u8], ) -> Pin<Box<dyn Future<Output = Option<V>> + Send + 'async_trait>>
where Self: Sized + 'async_trait, V: 'async_trait + MlsEntity, 'life0: 'async_trait, 'life1: 'async_trait,

Read and return a value stored for ID k that implements the [MlsEntity] trait for deserialization. Read more
Source§

fn delete<'life0, 'life1, 'async_trait, V>( &'life0 self, id: &'life1 [u8], ) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>>
where V: 'async_trait + MlsEntity, Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Delete a value stored for ID k. Read more
Source§

impl PreKeyStore for Transaction

Source§

type Error = CryptoKeystoreError

Source§

fn prekey<'life0, 'async_trait>( &'life0 self, id: RawPreKeyId, ) -> Pin<Box<dyn Future<Output = Result<Option<RawPreKey>, Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Lookup prekey by ID.
Source§

fn remove<'life0, 'async_trait>( &'life0 self, id: RawPreKeyId, ) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Remove prekey by ID.

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.

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> 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> ErasedDestructor for T
where T: 'static,

§

impl<T> MaybeSendSync for T