Skip to main content

Transaction

Struct Transaction 

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

This is an in-flight transaction: all operations are buffered in memory, and only applied to the database on commit.

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 async fn save<E>( &self, entity: E, ) -> CryptoKeystoreResult<E::AutoGeneratedFields>

Save an entity into this transaction.

This is a multi-step process:

  • Adjust the entity by calling its pre_save() method.
  • Store the entity in an internal map.
    • Remove the entity from the set of deleted entities, if it was there.
  • On commit, actually persist the entity into the supplied database.
Source

pub async fn remove<E>(&self, id: &E::PrimaryKey) -> CryptoKeystoreResult<()>

Remove an entity by its primary key.

Where the primary key has a distinct borrowed form, consider Self::remove_borrowed.

Note that this doesn’t return whether or not anything was actually removed because that won’t happen until the transaction is committed.

Source

pub async fn remove_borrowed<E>( &self, id: &E::BorrowedPrimaryKey, ) -> CryptoKeystoreResult<()>

Remove an entity by the borrowed form of its primary key.

Note that this doesn’t return whether or not anything was actually removed because that won’t happen until the transaction is committed.

Source

pub async fn restore<E>( &self, id: &E::BorrowedPrimaryKey, ) -> CryptoKeystoreResult<()>

Restore an entity that was deleted in this transaction by removing it from the deleted list. This is idempotent: if the entity doesn’t exist in the deleted list, do nothing.

NOTE: This will only work if the entity has been added in an earlier transaction, because otherwise, removing its id from the deleted list wouldn’t suffice: we’d need to replay its insertion.

Trait Implementations§

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<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: &'life1 <E as BorrowPrimaryKey>::BorrowedPrimaryKey, ) -> Pin<Box<dyn Future<Output = CryptoKeystoreResult<Option<E>>> + Send + 'async_trait>>
where E: 'static + EntityGetBorrowed + Clone + Send + Sync + 'async_trait, E::PrimaryKey: Borrow<E::BorrowedPrimaryKey>, for<'a> &'a E::BorrowedPrimaryKey: KeyType, 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<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<E>>> + Send + 'async_trait>>
where E: 'static + Entity + SearchableEntity<SearchKey> + Clone + Send + Sync + 'async_trait, SearchKey: KeyType + '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<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 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> 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<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