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
.
pub fn get_tree( &self, col: ColId, key: &[u8], ) -> Result<Option<Arc<RwLock<Box<dyn TreeReader + Send + Sync>>>>>
pub fn get_root( &self, col: ColId, key: &[u8], ) -> Result<Option<(Vec<u8>, Children)>>
pub fn get_node( &self, col: ColId, node_address: NodeAddress, ) -> Result<Option<(Vec<u8>, Children)>>
pub fn get_node_children( &self, col: ColId, node_address: NodeAddress, ) -> Result<Option<Children>>
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.
👎Deprecated: This method will be removed in future versions. Use commit_changes_bytes
instead
commit_changes_bytes
insteadCommit a set of changes to the database.
This method passes values as Arc<Vec<u8>>
potentially eliminating an extra copy.
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.
pub fn get_num_column_value_entries(&self, col: ColId) -> Result<u64>
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.