pub struct DB(/* private fields */);Expand description
Database
Implementations§
Source§impl<'a> DB
impl<'a> DB
pub fn path(&self) -> &Path
pub fn read_only(&self) -> bool
pub fn opened(&self) -> bool
Sourcepub fn begin_tx(&'a self) -> Result<TxGuard<'a>, Error>
pub fn begin_tx(&'a self) -> Result<TxGuard<'a>, Error>
Starts a new transaction. Multiple read-only transactions can be used concurrently but only one write transaction can be used at a time.
Transactions should not be dependent on one another.
If a long running read transaction (for example, a snapshot transaction) is needed, you might want to set DBBuilder.initial_mmap_size to a large enough value to avoid potential blocking of write transaction.
Sourcepub fn begin_rw_tx(&'a mut self) -> Result<RWTxGuard<'a>, Error>
pub fn begin_rw_tx(&'a mut self) -> Result<RWTxGuard<'a>, Error>
Starts a new writable transaction. Multiple read-only transactions can be used concurrently but only one write transaction can be used at a time.
Transactions should not be dependent on one another.
If a long running read transaction (for example, a snapshot transaction) is needed, you might want to set DBBuilder.initial_mmap_size to a large enough value to avoid potential blocking of write transaction.
Sourcepub fn update<'b>(
&mut self,
handler: Box<dyn FnMut(&mut Tx) -> Result<(), String> + 'b>,
) -> Result<(), Error>
pub fn update<'b>( &mut self, handler: Box<dyn FnMut(&mut Tx) -> Result<(), String> + 'b>, ) -> Result<(), Error>
shorthand for db.begin_rw_tx with additional guarantee for panic safery
Sourcepub fn view<'b>(
&self,
handler: Box<dyn Fn(&Tx) -> Result<(), String> + 'b>,
) -> Result<(), Error>
pub fn view<'b>( &self, handler: Box<dyn Fn(&Tx) -> Result<(), String> + 'b>, ) -> Result<(), Error>
shorthand for db.begin_tx with additional guarantee for panic safery
Sourcepub fn batch(
&mut self,
handler: Box<dyn Fn(&mut Tx) -> Result<(), String> + Send>,
) -> Result<(), Error>
pub fn batch( &mut self, handler: Box<dyn Fn(&mut Tx) -> Result<(), String> + Send>, ) -> Result<(), Error>
Calls fn as part of a batch. It behaves similar to Update, except:
-
concurrent batch calls can be combined into a single transaction.
-
the function passed to batch may be called multiple times, regardless of whether it returns error or not.
This means that Batch function side effects must be idempotent and take permanent effect only after a successful return is seen in caller.
The maximum batch size and delay can be adjusted with DBBuilder.batch_size and DBBuilder.batch_delay, respectively.
Batch is only useful when there are multiple threads calling it. While calling it multiple times from single thread just blocks thread for each single batch call
pub fn stats(&self) -> Stats
pub fn info(&self) -> Info
pub fn meta(&self) -> Result<Meta, Error>
Trait Implementations§
Auto Trait Implementations§
impl Freeze for DB
impl !RefUnwindSafe for DB
impl Send for DB
impl Sync for DB
impl Unpin for DB
impl !UnwindSafe for DB
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more