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
impl Transaction
Sourcepub fn conn(&self) -> CryptoKeystoreResult<TransactionConnection>
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
impl Transaction
Sourcepub 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>
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
impl Drop for Transaction
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<Arc<E>>>> + Send + 'async_trait>>
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>>
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,
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,
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<Arc<E>>>> + Send + 'async_trait>>
fn load_all<'life0, 'async_trait, E>( &'life0 self, ) -> Pin<Box<dyn Future<Output = CryptoKeystoreResult<Vec<Arc<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<Arc<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<Arc<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<Arc<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<Arc<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<'a> From<&'a Transaction> for Transactionlike<'a>
impl<'a> From<&'a Transaction> for Transactionlike<'a>
Source§fn from(value: &'a Transaction) -> Self
fn from(value: &'a Transaction) -> Self
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 more