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
impl Database
sourcepub fn create(path: impl AsRef<Path>) -> Result<Database, Error>
pub fn create(path: impl AsRef<Path>) -> Result<Database, Error>
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
sourcepub fn open(path: impl AsRef<Path>) -> Result<Database, Error>
pub fn open(path: impl AsRef<Path>) -> Result<Database, Error>
Opens an existing redb database.
sourcepub fn builder() -> Builder
pub fn builder() -> Builder
Convenience method for Builder::new
sourcepub fn set_write_strategy(&self, strategy: WriteStrategy) -> Result<(), Error>
pub fn set_write_strategy(&self, strategy: WriteStrategy) -> Result<(), Error>
Changes the write strategy of the database for future WriteTransaction
s.
Calling this method will invalidate all existing crate::Savepoint
s.
Note: Changing to the WriteStrategy::Checksum
strategy can take a long time, as checksums
will need to be calculated for every entry in the database
sourcepub fn begin_write(&self) -> Result<WriteTransaction<'_>, Error>
pub fn begin_write(&self) -> Result<WriteTransaction<'_>, Error>
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.
sourcepub fn begin_read(&self) -> Result<ReadTransaction<'_>, Error>
pub fn begin_read(&self) -> Result<ReadTransaction<'_>, Error>
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