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_with_outcome_check<T, E>(
&self,
savepoint_name: &str,
operation: impl AsyncFnOnce() -> Result<T, E>,
map_err: impl Fn(&'static str) -> Box<dyn FnOnce(CryptoKeystoreError) -> E>,
outcome_check: impl FnOnce(&Result<T, E>) -> bool,
) -> Result<T, E>
pub async fn with_savepoint_with_outcome_check<T, E>( &self, savepoint_name: &str, operation: impl AsyncFnOnce() -> Result<T, E>, map_err: impl Fn(&'static str) -> Box<dyn FnOnce(CryptoKeystoreError) -> E>, outcome_check: impl FnOnce(&Result<T, E>) -> bool, ) -> Result<T, E>
Do an operation within the context of a savepoint, with a custom check if the outcome indicates the savepoint should commit.
See Self::with_savepoint.
The only difference here is the outcome_check: this function is used to determine
whether or not the savepoint should be committed or rolled back. If it returns true,
the savepoint is committed. If false, it is rolled back.
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.
This is like Self::with_savepoint_with_outcome_check, but it uses a default outcome check: Result::is_ok.
Source§impl Transaction
impl Transaction
Sourcepub fn externally_modified(&self) -> bool
pub fn externally_modified(&self) -> bool
Whether the database detected external modifications to the connection when this transaction was created.
If there is only a single live connection to the database, this will never return true.
That can only happen if multiple connections are interleaving transactions on the DB.
Sourcepub fn inbox_message_next_arrival_sequence(&self) -> u64
pub fn inbox_message_next_arrival_sequence(&self) -> u64
Get the next arrival sequence number for an inbox message.
Multiple calls will return increasing integers. It’s fine if any given conversation has gaps between messages; only the relative ordering matters.
Not idempotent, but the u64 space is big enough that it shouldn’t matter.
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