pub trait HoprDbGeneralModelOperations {
// Required methods
fn conn(&self, target_db: TargetDb) -> &DatabaseConnection;
fn begin_transaction_in_db<'life0, 'async_trait>(
&'life0 self,
target: TargetDb,
) -> Pin<Box<dyn Future<Output = Result<OpenTransaction>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn import_logs_db<'async_trait>(
self,
src_dir: PathBuf,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait;
// Provided methods
fn begin_transaction<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<OpenTransaction>> + Send + 'async_trait>>
where Self: Sync + 'async_trait,
'life0: 'async_trait { ... }
fn nest_transaction_in_db<'life0, 'life1, 'async_trait>(
&'life0 self,
tx: OptTx<'life1>,
target_db: TargetDb,
) -> Pin<Box<dyn Future<Output = Result<OpenTransaction>> + Send + 'async_trait>>
where Self: Sync + 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait { ... }
fn nest_transaction<'life0, 'life1, 'async_trait>(
&'life0 self,
tx: OptTx<'life1>,
) -> Pin<Box<dyn Future<Output = Result<OpenTransaction>> + Send + 'async_trait>>
where Self: Sync + 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait { ... }
}Required Methods§
Sourcefn conn(&self, target_db: TargetDb) -> &DatabaseConnection
fn conn(&self, target_db: TargetDb) -> &DatabaseConnection
Returns reference to the database connection.
Can be used in case transaction is not needed, but
users should aim to use HoprDbGeneralModelOperations::begin_transaction
and HoprDbGeneralModelOperations::nest_transaction as much as possible.
Sourcefn begin_transaction_in_db<'life0, 'async_trait>(
&'life0 self,
target: TargetDb,
) -> Pin<Box<dyn Future<Output = Result<OpenTransaction>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn begin_transaction_in_db<'life0, 'async_trait>(
&'life0 self,
target: TargetDb,
) -> Pin<Box<dyn Future<Output = Result<OpenTransaction>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Creates a new transaction.
Sourcefn import_logs_db<'async_trait>(
self,
src_dir: PathBuf,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
fn import_logs_db<'async_trait>(
self,
src_dir: PathBuf,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
Import logs database from a snapshot directory.
Replaces all data in the current logs database with data from a snapshot’s
hopr_logs.db file. This is used for fast synchronization during node startup.
§Process
- Attaches the source database from the snapshot directory
- Clears existing data from all logs-related tables
- Copies all data from the snapshot database
- Detaches the source database
All operations are performed within a single transaction for atomicity.
§Arguments
src_dir- Directory containing the extracted snapshot withhopr_logs.db
§Returns
Ok(()) on successful import, or DbSqlError::Construction if the source
database doesn’t exist or the import operation fails.
§Errors
- Returns error if
hopr_logs.dbis not found in the source directory - Returns error if SQLite ATTACH, data transfer, or DETACH operations fail
- All database errors are wrapped in
DbSqlError::Construction
§Example
let snapshot_dir = PathBuf::from("/tmp/snapshot_extracted");
db.import_logs_db(snapshot_dir).await?;Provided Methods§
Sourcefn begin_transaction<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<OpenTransaction>> + Send + 'async_trait>>where
Self: Sync + 'async_trait,
'life0: 'async_trait,
fn begin_transaction<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<OpenTransaction>> + Send + 'async_trait>>where
Self: Sync + 'async_trait,
'life0: 'async_trait,
Same as HoprDbGeneralModelOperations::begin_transaction_in_db with default TargetDb.
Sourcefn nest_transaction_in_db<'life0, 'life1, 'async_trait>(
&'life0 self,
tx: OptTx<'life1>,
target_db: TargetDb,
) -> Pin<Box<dyn Future<Output = Result<OpenTransaction>> + Send + 'async_trait>>where
Self: Sync + 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn nest_transaction_in_db<'life0, 'life1, 'async_trait>(
&'life0 self,
tx: OptTx<'life1>,
target_db: TargetDb,
) -> Pin<Box<dyn Future<Output = Result<OpenTransaction>> + Send + 'async_trait>>where
Self: Sync + 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Creates a nested transaction inside the given transaction.
If None is given, behaves exactly as HoprDbGeneralModelOperations::begin_transaction.
This method is useful for creating APIs that should be agnostic whether they are being run from an existing transaction or without it (via OptTx).
If tx is Some, the target_db must match with the one in tx. In other words,
nesting across different databases is forbidden and the method will panic.
Sourcefn nest_transaction<'life0, 'life1, 'async_trait>(
&'life0 self,
tx: OptTx<'life1>,
) -> Pin<Box<dyn Future<Output = Result<OpenTransaction>> + Send + 'async_trait>>where
Self: Sync + 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn nest_transaction<'life0, 'life1, 'async_trait>(
&'life0 self,
tx: OptTx<'life1>,
) -> Pin<Box<dyn Future<Output = Result<OpenTransaction>> + Send + 'async_trait>>where
Self: Sync + 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Same as HoprDbGeneralModelOperations::nest_transaction_in_db with default TargetDb.