Trait cuprate_blockchain::OpenTables
source · pub trait OpenTables<'env, Ro, Rw>{
// Required methods
fn open_tables(
&'env self,
tx_ro: &Ro,
) -> Result<impl TablesIter, RuntimeError>;
fn open_tables_mut(
&'env self,
tx_rw: &Rw,
) -> Result<impl TablesMut, RuntimeError>;
fn create_tables(&'env self, tx_rw: &Rw) -> Result<(), RuntimeError>;
}Expand description
Open all tables at once.
This trait encapsulates the functionality of opening all tables at once.
It can be seen as the “constructor” for the Tables object.
Note that this is already implemented on cuprate_database::EnvInner, thus:
- You don’t need to implement this
- It can be called using
env_inner.open_tables()notation
§Example
use cuprate_blockchain::{
cuprate_database::{Env, EnvInner},
config::ConfigBuilder,
tables::{Tables, TablesMut},
OpenTables,
};
// Create a configuration for the database environment.
let tmp_dir = tempfile::tempdir()?;
let db_dir = tmp_dir.path().to_owned();
let config = ConfigBuilder::new()
.db_directory(db_dir.into())
.build();
// Initialize the database environment.
let env = cuprate_blockchain::open(config)?;
// Open up a transaction.
let env_inner = env.env_inner();
let tx_rw = env_inner.tx_rw()?;
// Open _all_ tables in write mode using [`OpenTables::open_tables_mut`].
// Note how this is being called on `env_inner`.
// |
// v
let mut tables = env_inner.open_tables_mut(&tx_rw)?;Required Methods§
sourcefn open_tables(&'env self, tx_ro: &Ro) -> Result<impl TablesIter, RuntimeError>
fn open_tables(&'env self, tx_ro: &Ro) -> Result<impl TablesIter, RuntimeError>
Open all tables in read/iter mode.
This calls EnvInner::open_db_ro on all database tables
and returns a structure that allows access to all tables.
§Errors
This will only return RuntimeError::Io if it errors.
As all tables are created upon crate::open,
this function will never error because a table doesn’t exist.
sourcefn open_tables_mut(
&'env self,
tx_rw: &Rw,
) -> Result<impl TablesMut, RuntimeError>
fn open_tables_mut( &'env self, tx_rw: &Rw, ) -> Result<impl TablesMut, RuntimeError>
Open all tables in read-write mode.
This calls EnvInner::open_db_rw on all database tables
and returns a structure that allows access to all tables.
§Errors
This will only return RuntimeError::Io on errors.
sourcefn create_tables(&'env self, tx_rw: &Rw) -> Result<(), RuntimeError>
fn create_tables(&'env self, tx_rw: &Rw) -> Result<(), RuntimeError>
Create all database tables.
This will create all the Tables
found in tables.
§Errors
This will only return RuntimeError::Io on errors.