pub struct Db { /* private fields */ }
Expand description
Database instance.
Implementations§
source§impl Db
impl Db
sourcepub fn open(options: &Options) -> Result<Db>
pub fn open(options: &Options) -> Result<Db>
Open the database with given options. An error will be returned if the database does not exist.
sourcepub fn open_or_create(options: &Options) -> Result<Db>
pub fn open_or_create(options: &Options) -> Result<Db>
Open the database using given options. If the database does not exist it will be created empty.
sourcepub fn open_read_only(options: &Options) -> Result<Db>
pub fn open_read_only(options: &Options) -> Result<Db>
Open an existing database in read-only mode.
sourcepub fn get(&self, col: ColId, key: &[u8]) -> Result<Option<Value>>
pub fn get(&self, col: ColId, key: &[u8]) -> Result<Option<Value>>
Get a value in a specified column by key. Returns None
if the key does not exist.
sourcepub fn get_size(&self, col: ColId, key: &[u8]) -> Result<Option<u32>>
pub fn get_size(&self, col: ColId, key: &[u8]) -> Result<Option<u32>>
Get value size by key. Returns None
if the key does not exist.
sourcepub fn iter(&self, col: ColId) -> Result<BTreeIterator<'_>>
pub fn iter(&self, col: ColId) -> Result<BTreeIterator<'_>>
Iterate over all ordered key-value pairs. Only supported for columns configured with
btree_indexed
.
sourcepub fn commit_changes<I>(&self, tx: I) -> Result<()>
pub fn commit_changes<I>(&self, tx: I) -> Result<()>
Commit a set of changes to the database.
sourcepub fn num_columns(&self) -> u8
pub fn num_columns(&self) -> u8
Returns the number of columns in the database.
sourcepub fn iter_column_while(
&self,
c: ColId,
f: impl FnMut(ValueIterState) -> bool,
) -> Result<()>
pub fn iter_column_while( &self, c: ColId, f: impl FnMut(ValueIterState) -> bool, ) -> Result<()>
Iterate a column and call a function for each value. This is only supported for columns with
btree_index
set to false
. Iteration order is unspecified.
Unlike get
the iteration may not include changes made in recent commit
calls.
sourcepub fn write_stats_text(
&self,
writer: &mut impl Write,
column: Option<u8>,
) -> Result<()>
pub fn write_stats_text( &self, writer: &mut impl Write, column: Option<u8>, ) -> Result<()>
Dump full database stats to the text output.
sourcepub fn clear_stats(&self, column: Option<u8>) -> Result<()>
pub fn clear_stats(&self, column: Option<u8>) -> Result<()>
Reset internal database statistics for the database or specified column.
sourcepub fn dump(&self, check_param: CheckOptions) -> Result<()>
pub fn dump(&self, check_param: CheckOptions) -> Result<()>
Print database contents in text form to stderr.
sourcepub fn stats(&self) -> StatSummary
pub fn stats(&self) -> StatSummary
Get database statistics.
sourcepub fn add_column(
options: &mut Options,
new_column_options: ColumnOptions,
) -> Result<()>
pub fn add_column( options: &mut Options, new_column_options: ColumnOptions, ) -> Result<()>
Add a new column with options specified by new_column_options
.
sourcepub fn drop_last_column(options: &mut Options) -> Result<()>
pub fn drop_last_column(options: &mut Options) -> Result<()>
Remove last column from the database. Db must be close when called.
sourcepub fn reset_column(
options: &mut Options,
index: u8,
new_options: Option<ColumnOptions>,
) -> Result<()>
pub fn reset_column( options: &mut Options, index: u8, new_options: Option<ColumnOptions>, ) -> Result<()>
Truncate a column from the database, optionally changing its options. Db must be close when called.