Trait cuprate_database::EnvInner

source ·
pub trait EnvInner<'env, Ro, Rw>
where Self: 'env, Ro: TxRo<'env>, Rw: TxRw<'env>,
{ // 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§

source

fn tx_ro(&'env self) -> Result<Ro, RuntimeError>

Create a read-only transaction.

§Errors

This will only return RuntimeError::Io if it errors.

source

fn tx_rw(&'env self) -> Result<Rw, RuntimeError>

Create a read/write transaction.

§Errors

This will only return RuntimeError::Io if it errors.

source

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.

source

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.

source

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.

source

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
  • redb will create the table if it does not exist

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl<'env> EnvInner<'env, RoTxn<'env>, RefCell<RwTxn<'env>>> for RwLockReadGuard<'env, Env>
where Self: 'env,

source§

fn tx_ro(&'env self) -> Result<RoTxn<'env>, RuntimeError>

source§

fn tx_rw(&'env self) -> Result<RefCell<RwTxn<'env>>, RuntimeError>

source§

fn open_db_ro<T: Table>( &self, tx_ro: &RoTxn<'env>, ) -> Result<impl DatabaseRo<T> + DatabaseIter<T>, RuntimeError>

source§

fn open_db_rw<T: Table>( &self, tx_rw: &RefCell<RwTxn<'env>>, ) -> Result<impl DatabaseRw<T>, RuntimeError>

source§

fn create_db<T: Table>( &self, tx_rw: &RefCell<RwTxn<'env>>, ) -> Result<(), RuntimeError>

source§

fn clear_db<T: Table>( &self, tx_rw: &mut RefCell<RwTxn<'env>>, ) -> Result<(), RuntimeError>

Implementors§