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 = unsafe { Database::create(filename, db_max_size)? };
let write_txn = db.begin_write()?;
{
let mut table = write_txn.open_table(TABLE)?;
table.insert(&0, &0)?;
}
write_txn.commit()?;
Implementations
sourceimpl Database
impl Database
sourcepub unsafe fn create(
path: impl AsRef<Path>,
db_size: usize
) -> Result<Database, Error>
pub unsafe fn create(
path: impl AsRef<Path>,
db_size: usize
) -> 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
db_size
: the maximum size in bytes of the database.
Safety
The file referenced by path
must not be concurrently modified by any other process
sourcepub unsafe fn open(path: impl AsRef<Path>) -> Result<Database, Error>
pub unsafe fn open(path: impl AsRef<Path>) -> Result<Database, Error>
Opens an existing redb database.
Safety
The file referenced by path
must not be concurrently modified by any other process
sourcepub fn builder() -> DatabaseBuilder
pub fn builder() -> DatabaseBuilder
Convenience method for DatabaseBuilder::new
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
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
Auto Trait Implementations
impl RefUnwindSafe for Database
impl Send for Database
impl Sync for Database
impl Unpin for Database
impl UnwindSafe for Database
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more