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
impl Transaction
Sourcepub async fn save<E>(
&self,
entity: E,
) -> CryptoKeystoreResult<E::AutoGeneratedFields>
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.
Sourcepub async fn remove<E>(&self, id: &E::PrimaryKey) -> CryptoKeystoreResult<()>where
E: Entity + EntityDatabaseMutation,
pub async fn remove<E>(&self, id: &E::PrimaryKey) -> CryptoKeystoreResult<()>where
E: Entity + EntityDatabaseMutation,
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.
Sourcepub async fn remove_borrowed<E>(
&self,
id: &E::BorrowedPrimaryKey,
) -> CryptoKeystoreResult<()>where
E: EntityDeleteBorrowed + BorrowPrimaryKey,
pub async fn remove_borrowed<E>(
&self,
id: &E::BorrowedPrimaryKey,
) -> CryptoKeystoreResult<()>where
E: EntityDeleteBorrowed + BorrowPrimaryKey,
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.
Sourcepub async fn restore<E>(
&self,
id: &E::BorrowedPrimaryKey,
) -> CryptoKeystoreResult<()>where
E: EntityDeleteBorrowed + BorrowPrimaryKey,
pub async fn restore<E>(
&self,
id: &E::BorrowedPrimaryKey,
) -> CryptoKeystoreResult<()>where
E: EntityDeleteBorrowed + BorrowPrimaryKey,
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
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>>
fn get<'life0, 'life1, 'async_trait, E>( &'life0 self, id: &'life1 E::PrimaryKey, ) -> Pin<Box<dyn Future<Output = CryptoKeystoreResult<Option<E>>> + Send + 'async_trait>>
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,
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,
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>>
fn count<'life0, 'async_trait, E>( &'life0 self, ) -> Pin<Box<dyn Future<Output = CryptoKeystoreResult<u32>> + Send + 'async_trait>>
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>>
fn load_all<'life0, 'async_trait, E>( &'life0 self, ) -> Pin<Box<dyn Future<Output = CryptoKeystoreResult<Vec<E>>> + Send + 'async_trait>>
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>>
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>>
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,
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,
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,
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,
Source§impl OpenMlsKeyStore for Transaction
impl OpenMlsKeyStore for Transaction
Source§type Error = CryptoKeystoreError
type Error = CryptoKeystoreError
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>>
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>>
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,
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,
k that implements the
[MlsEntity] trait for deserialization. Read moreSource§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,
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,
k. Read moreSource§impl PreKeyStore for Transaction
impl PreKeyStore for Transaction
Auto Trait Implementations§
impl !Freeze for Transaction
impl !RefUnwindSafe for Transaction
impl Send for Transaction
impl Sync for Transaction
impl Unpin for Transaction
impl UnsafeUnpin for Transaction
impl !UnwindSafe for Transaction
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
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