pub struct Prevayler<D, T, S> { /* private fields */ }
Expand description
The main Prevayler struct. This wrapper your data and save each executed transaction to the redolog.
Avoid creating it directly. Use PrevaylerBuilder
instead.
Implementations§
Source§impl<D, T, S> Prevayler<D, T, S>
impl<D, T, S> Prevayler<D, T, S>
Sourcepub async fn execute_transaction<TR>(
&mut self,
transaction: TR,
) -> PrevaylerResult<()>
pub async fn execute_transaction<TR>( &mut self, transaction: TR, ) -> PrevaylerResult<()>
Execute the given transaction and write it to the redolog. You need to have a mutable reference to the prevayler. If you are in a multithread program, you can wrapp the prevayler behind a Mutex, RwLock or anyother concurrency control system.
This method returns a PrevaylerResult
. If it the error is returned a PrevaylerError::SerializationError
, then you can guarantee that the prevailed state did not change. But, if it returns the error a PrevaylerError::IOError
, than the data did change but the redolog is in a inconsistent state. A solution would be to force a program restart.
Sourcepub async fn execute_transaction_with_query<TR, R>(
&mut self,
transaction: TR,
) -> PrevaylerResult<R>
pub async fn execute_transaction_with_query<TR, R>( &mut self, transaction: TR, ) -> PrevaylerResult<R>
Similar to the execute_transaction
. But this execute TransactionWithQuery and returns its result.
Sourcepub async fn execute_transaction_panic_safe<TR>(
&mut self,
transaction: TR,
) -> PrevaylerResult<()>
pub async fn execute_transaction_panic_safe<TR>( &mut self, transaction: TR, ) -> PrevaylerResult<()>
Like execute_transaction, it executes the give transaction and write it to the redolog. But, if a transaction panics for some reason, this gurantees that the prevailed state will not be changed. This gurantee comes wiht a cost. The entire prevailed state is cloned everytime that a transaction is executed.
Think twice before using this method. Your transactions should probably not be able to panic. Try to do any code that can fail before the transaction and only do the state change inside it.
Sourcepub async fn snapshot(&mut self) -> PrevaylerResult<()>where
S: Serializer<T>,
pub async fn snapshot(&mut self) -> PrevaylerResult<()>where
S: Serializer<T>,
Does a snapshot of the prevailed state. This requires that the Serializer know how to serialize the prevailed state.