Trait cuprate_database::EnvInner

source ·
pub trait EnvInner<'env> {
    type Ro<'tx>: TxRo<'tx>;
    type Rw<'tx>: TxRw<'tx>;

    // Required methods
    fn tx_ro(&self) -> Result<Self::Ro<'_>, RuntimeError>;
    fn tx_rw(&self) -> Result<Self::Rw<'_>, RuntimeError>;
    fn open_db_ro<T: Table>(
        &self,
        tx_ro: &Self::Ro<'_>,
    ) -> Result<impl DatabaseRo<T> + DatabaseIter<T>, RuntimeError>;
    fn open_db_rw<T: Table>(
        &self,
        tx_rw: &Self::Rw<'_>,
    ) -> Result<impl DatabaseRw<T>, RuntimeError>;
    fn create_db<T: Table>(
        &self,
        tx_rw: &Self::Rw<'_>,
    ) -> Result<(), RuntimeError>;
    fn clear_db<T: Table>(
        &self,
        tx_rw: &mut Self::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::create_db for creating tables.

§Invariant

The first time you open/create tables, you must use EnvInner::create_db to set the proper flags / Key comparison for the heed backend.

Subsequent table opens will follow the flags/ordering, but only if EnvInner::create_db was the first function to open/create it.

Required Associated Types§

source

type Ro<'tx>: TxRo<'tx>

The read-only transaction type of the backend.

'tx is the lifetime of the transaction itself.

source

type Rw<'tx>: TxRw<'tx>

The read-write transaction type of the backend.

'tx is the lifetime of the transaction itself.

Required Methods§

source

fn tx_ro(&self) -> Result<Self::Ro<'_>, RuntimeError>

Create a read-only transaction.

§Errors

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

source

fn tx_rw(&self) -> Result<Self::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: &Self::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_inner.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.

§Invariant

The first time you open/create tables, you must use EnvInner::create_db to set the proper flags / Key comparison for the heed backend.

Subsequent table opens will follow the flags/ordering, but only if EnvInner::create_db was the first function to open/create it.

source

fn open_db_rw<T: Table>( &self, tx_rw: &Self::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.

§Invariant

The first time you open/create tables, you must use EnvInner::create_db to set the proper flags / Key comparison for the heed backend.

Subsequent table opens will follow the flags/ordering, but only if EnvInner::create_db was the first function to open/create it.

source

fn create_db<T: Table>(&self, tx_rw: &Self::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.

§Invariant

The first time you open/create tables, you must use EnvInner::create_db to set the proper flags / Key comparison for the heed backend.

Subsequent table opens will follow the flags/ordering, but only if EnvInner::create_db was the first function to open/create it.

source

fn clear_db<T: Table>( &self, tx_rw: &mut Self::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 return RuntimeError::Io on normal errors.

If the specified table is not created upon before this function is called, this will return RuntimeError::TableNotFound.

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

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

source§

type Ro<'a> = RoTxn<'a>

source§

type Rw<'a> = RefCell<RwTxn<'a>>

source§

fn tx_ro(&self) -> Result<Self::Ro<'_>, RuntimeError>

source§

fn tx_rw(&self) -> Result<Self::Rw<'_>, RuntimeError>

source§

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

source§

fn open_db_rw<T: Table>( &self, tx_rw: &Self::Rw<'_>, ) -> Result<impl DatabaseRw<T>, RuntimeError>

source§

fn create_db<T: Table>(&self, tx_rw: &Self::Rw<'_>) -> Result<(), RuntimeError>

source§

fn clear_db<T: Table>( &self, tx_rw: &mut Self::Rw<'_>, ) -> Result<(), RuntimeError>

Implementors§