redb

Struct Database

Source
pub struct Database { /* private fields */ }
Expand description

Opened redb database file

Use Self::begin_read to get a ReadTransaction object that can be used to read from the database Use Self::begin_write to get a WriteTransaction object that can be used to read or write to the database

Multiple reads may be performed concurrently, with each other, and with writes. Only a single write may be in progress at a time.

§Examples

Basic usage:

use redb::*;
const TABLE: TableDefinition<u64, u64> = TableDefinition::new("my_data");

let db = Database::create(filename)?;
let write_txn = db.begin_write()?;
{
    let mut table = write_txn.open_table(TABLE)?;
    table.insert(&0, &0)?;
}
write_txn.commit()?;

Implementations§

Source§

impl Database

Source

pub fn create(path: impl AsRef<Path>) -> Result<Database, DatabaseError>

Opens the specified file as a redb database.

  • if the file does not exist, or is an empty file, a new database will be initialized in it
  • if the file is a valid redb database, it will be opened
  • otherwise this function will return an error
Source

pub fn open(path: impl AsRef<Path>) -> Result<Database, DatabaseError>

Opens an existing redb database.

Source

pub fn check_integrity(&mut self) -> Result<bool, DatabaseError>

Force a check of the integrity of the database file, and repair it if possible.

Note: Calling this function is unnecessary during normal operation. redb will automatically detect and recover from crashes, power loss, and other unclean shutdowns. This function is quite slow and should only be used when you suspect the database file may have been modified externally to redb, or that a redb bug may have left the database in a corrupted state.

Returns Ok(true) if the database passed integrity checks; Ok(false) if it failed but was repaired, and Err(Corrupted) if the check failed and the file could not be repaired

Source

pub fn compact(&mut self) -> Result<bool, CompactionError>

Compacts the database file

Returns true if compaction was performed, and false if no futher compaction was possible

Source

pub fn builder() -> Builder

Convenience method for Builder::new

Source

pub fn begin_write(&self) -> Result<WriteTransaction, TransactionError>

Begins a write transaction

Returns a WriteTransaction which may be used to read/write to the database. Only a single write may be in progress at a time. If a write is in progress, this function will block until it completes.

Source

pub fn begin_read(&self) -> Result<ReadTransaction, TransactionError>

Begins a read transaction

Captures a snapshot of the database, so that only data committed before calling this method is visible in the transaction

Returns a ReadTransaction which may be used to read from the database. Read transactions may exist concurrently with writes

Trait Implementations§

Source§

impl Debug for Database

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.

Layout§

Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...) attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.

Size: 16 bytes