pub struct DB { /* private fields */ }Expand description
The core database handle.
Implementations§
Source§impl DB
impl DB
Sourcepub fn open(options: DbOptions, path: impl AsRef<Path>) -> Result<Self>
pub fn open(options: DbOptions, path: impl AsRef<Path>) -> Result<Self>
Open or create a database.
pub fn put(&self, key: &[u8], value: &[u8]) -> Result<()>
pub fn put_with_options( &self, write_options: &WriteOptions, key: &[u8], value: &[u8], ) -> Result<()>
pub fn delete(&self, key: &[u8]) -> Result<()>
pub fn delete_with_options( &self, write_options: &WriteOptions, key: &[u8], ) -> Result<()>
Sourcepub fn delete_range(&self, begin: &[u8], end: &[u8]) -> Result<()>
pub fn delete_range(&self, begin: &[u8], end: &[u8]) -> Result<()>
Delete all keys in the range [begin, end).
pub fn delete_range_with_options( &self, write_options: &WriteOptions, begin: &[u8], end: &[u8], ) -> Result<()>
pub fn write(&self, batch: WriteBatch) -> Result<()>
pub fn write_with_options( &self, batch: WriteBatch, write_options: &WriteOptions, ) -> Result<()>
pub fn get(&self, key: &[u8]) -> Result<Option<Vec<u8>>>
pub fn get_with_options( &self, options: &ReadOptions, key: &[u8], ) -> Result<Option<Vec<u8>>>
Sourcepub fn iter(&self) -> Result<DBIterator>
pub fn iter(&self) -> Result<DBIterator>
Create a forward iterator over the database.
Sourcepub fn iter_with_options(&self, options: &ReadOptions) -> Result<DBIterator>
pub fn iter_with_options(&self, options: &ReadOptions) -> Result<DBIterator>
Create a forward iterator with options.
Uses streaming TableIterators for SST files (O(1 block) memory per SST) instead of loading entire tables into memory.
Sourcepub fn iter_with_range(
&self,
options: &ReadOptions,
lower_bound: Option<&[u8]>,
upper_bound: Option<&[u8]>,
) -> Result<DBIterator>
pub fn iter_with_range( &self, options: &ReadOptions, lower_bound: Option<&[u8]>, upper_bound: Option<&[u8]>, ) -> Result<DBIterator>
Create a forward iterator that only includes sources overlapping [lower_bound, upper_bound].
SST files outside this range are skipped entirely, avoiding costly block reads.
None bounds mean unbounded in that direction.
WARNING: Does NOT use prefix bloom filters. For prefix-scoped queries,
prefer iter_with_prefix() which is significantly faster.
Bounds from ReadOptions::iterate_lower_bound / iterate_upper_bound are
also applied if set, using the tighter of the two.
Sourcepub fn iter_with_prefix(
&self,
prefix: &[u8],
options: &ReadOptions,
) -> Result<DBIterator>
pub fn iter_with_prefix( &self, prefix: &[u8], options: &ReadOptions, ) -> Result<DBIterator>
Create a prefix-bounded iterator with full options support.
Uses prefix bloom filters to skip SST files that don’t contain the prefix,
and stops iteration as soon as the prefix boundary is crossed.
Significantly faster than iter_with_range() for prefix-scoped queries.
Supports ReadOptions::iterate_lower_bound / iterate_upper_bound for
sub-range queries within a prefix, and snapshot for historical reads.
Sourcepub fn iter_with_batch(&self, batch: &WriteBatchWithIndex) -> Result<DBIterator>
pub fn iter_with_batch(&self, batch: &WriteBatchWithIndex) -> Result<DBIterator>
Create a forward iterator that merges uncommitted batch writes with the current DB state. Batch entries appear with sequence numbers above the current snapshot so they take precedence over existing data.
pub fn snapshot_seq(&self) -> SequenceNumber
Sourcepub fn snapshot(&self) -> Snapshot<'_>
pub fn snapshot(&self) -> Snapshot<'_>
Acquire a snapshot with RAII guard. The snapshot is automatically released
when the Snapshot is dropped — no manual release_snapshot() needed.
Sourcepub fn release_snapshot(&self, seq: SequenceNumber)
pub fn release_snapshot(&self, seq: SequenceNumber)
Release a previously acquired snapshot so compaction can reclaim its data.
pub fn path(&self) -> &Path
Sourcepub fn get_property(&self, name: &str) -> Option<String>
pub fn get_property(&self, name: &str) -> Option<String>
Get a database property.
Supported properties:
"num-files-at-level{N}"— number of SST files at level N"total-sst-size"— total size of all SST files in bytes"block-cache-usage"— approximate block cache entry count"compaction-pending"— “1” if compaction is needed, “0” otherwise"stats.bytes_written"— total user bytes written"stats.bytes_read"— total user bytes read"stats.compactions_completed"— number of compactions completed"stats.compaction_bytes_written"— total bytes written during compaction"stats.flushes_completed"— number of memtable flushes"stats.block_cache_hits"— block cache hit count"stats.block_cache_misses"— block cache miss count"stats.cache_hit_rate"— block cache hit rate (0.0 to 1.0)
Sourcepub fn compact(&self) -> Result<()>
pub fn compact(&self) -> Result<()>
Run compaction if needed (L0 → L1 or Ln → Ln+1). Runs inline while holding locks for deterministic behavior.