Trait cuprate_database::EnvInner
source · pub trait EnvInner<'env, Ro, Rw>{
// Required methods
fn tx_ro(&'env self) -> Result<Ro, RuntimeError>;
fn tx_rw(&'env self) -> Result<Rw, RuntimeError>;
fn open_db_ro<T: Table>(
&self,
tx_ro: &Ro,
) -> Result<impl DatabaseRo<T> + DatabaseIter<T>, RuntimeError>;
fn open_db_rw<T: Table>(
&self,
tx_rw: &Rw,
) -> Result<impl DatabaseRw<T>, RuntimeError>;
fn create_db<T: Table>(&self, tx_rw: &Rw) -> Result<(), RuntimeError>;
fn clear_db<T: Table>(&self, tx_rw: &mut Rw) -> Result<(), RuntimeError>;
}Expand description
The inner Env type.
This type is created with Env::env_inner and represents
the type able to generate transactions and open tables.
§Locking behavior
As noted in Env::env_inner, this is a RwLockReadGuard
when using the heed backend, be aware of this and do
not hold onto an EnvInner for a long time.
§Tables
Note that when opening tables with EnvInner::open_db_ro,
they must be created first or else it will return error.
See EnvInner::open_db_rw and EnvInner::create_db for creating tables.
Required Methods§
sourcefn tx_ro(&'env self) -> Result<Ro, RuntimeError>
fn tx_ro(&'env self) -> Result<Ro, RuntimeError>
sourcefn tx_rw(&'env self) -> Result<Rw, RuntimeError>
fn tx_rw(&'env self) -> Result<Rw, RuntimeError>
sourcefn open_db_ro<T: Table>(
&self,
tx_ro: &Ro,
) -> Result<impl DatabaseRo<T> + DatabaseIter<T>, RuntimeError>
fn open_db_ro<T: Table>( &self, tx_ro: &Ro, ) -> Result<impl DatabaseRo<T> + DatabaseIter<T>, RuntimeError>
Open a database in read-only mode.
The returned value can have DatabaseRo
& DatabaseIter functions called on it.
This will open the database Table
passed as a generic to this function.
let db = env.open_db_ro::<Table>(&tx_ro);
// ^ ^
// database table table metadata
// (name, key/value type)§Errors
This will only return RuntimeError::Io on normal errors.
If the specified table is not created upon before this function is called,
this will return RuntimeError::TableNotFound.
sourcefn open_db_rw<T: Table>(
&self,
tx_rw: &Rw,
) -> Result<impl DatabaseRw<T>, RuntimeError>
fn open_db_rw<T: Table>( &self, tx_rw: &Rw, ) -> Result<impl DatabaseRw<T>, RuntimeError>
Open a database in read/write mode.
All DatabaseRo functions are also callable
with the returned DatabaseRw structure.
Note that DatabaseIter functions are not
available to DatabaseRw structures.
This will open the database Table
passed as a generic to this function.
§Errors
This will only return RuntimeError::Io on errors.
Implementation details: Both heed & redb backends create
the table with this function if it does not already exist. For safety and
clear intent, you should still consider using EnvInner::create_db instead.
sourcefn create_db<T: Table>(&self, tx_rw: &Rw) -> Result<(), RuntimeError>
fn create_db<T: Table>(&self, tx_rw: &Rw) -> Result<(), RuntimeError>
Create a database table.
This will create the database Table
passed as a generic to this function.
§Errors
This will only return RuntimeError::Io on errors.
sourcefn clear_db<T: Table>(&self, tx_rw: &mut Rw) -> Result<(), RuntimeError>
fn clear_db<T: Table>(&self, tx_rw: &mut Rw) -> Result<(), RuntimeError>
Clear all (key, value)’s from a database table.
This will delete all key and values in the passed
T: Table, but the table itself will continue to exist.
Note that this operation is tied to tx_rw, as such this
function’s effects can be aborted using TxRw::abort.
§Errors
This will only return RuntimeError::Io on normal errors.
If the specified table is not created upon before this function is called, this will return an error.
Implementation detail you should NOT rely on:
- This only panics on
heed redbwill create the table if it does not exist