pub struct DB { /* private fields */ }
Expand description
This DB is a schematized RocksDB wrapper where all data passed in and out are typed according to
Schema
s.
Implementations§
source§impl DB
impl DB
sourcepub fn open(
path: impl AsRef<Path>,
name: &'static str,
column_families: Vec<ColumnFamilyName>,
db_opts: &Options
) -> Result<Self>
pub fn open( path: impl AsRef<Path>, name: &'static str, column_families: Vec<ColumnFamilyName>, db_opts: &Options ) -> Result<Self>
Create db with all the column families provided if it doesn’t exist at path
; Otherwise,
try to open it with all the column families.
sourcepub fn open_readonly(
path: impl AsRef<Path>,
name: &'static str,
column_families: Vec<ColumnFamilyName>,
db_opts: &Options
) -> Result<Self>
pub fn open_readonly( path: impl AsRef<Path>, name: &'static str, column_families: Vec<ColumnFamilyName>, db_opts: &Options ) -> Result<Self>
Open db in readonly mode
Note that this still assumes there’s only one process that opens the same DB.
See open_as_secondary
sourcepub fn open_as_secondary<P: AsRef<Path>>(
primary_path: P,
secondary_path: P,
name: &'static str,
column_families: Vec<ColumnFamilyName>,
db_opts: &Options
) -> Result<Self>
pub fn open_as_secondary<P: AsRef<Path>>( primary_path: P, secondary_path: P, name: &'static str, column_families: Vec<ColumnFamilyName>, db_opts: &Options ) -> Result<Self>
Open db as secondary. This allows to read the DB in another process while it’s already opened for read / write in one (e.g. a Diem Node) https://github.com/facebook/rocksdb/blob/493f425e77043cc35ea2d89ee3c4ec0274c700cb/include/rocksdb/db.h#L176-L222
sourcepub fn get<S: Schema>(&self, schema_key: &S::Key) -> Result<Option<S::Value>>
pub fn get<S: Schema>(&self, schema_key: &S::Key) -> Result<Option<S::Value>>
Reads single record by key.
sourcepub fn put<S: Schema>(&self, key: &S::Key, value: &S::Value) -> Result<()>
pub fn put<S: Schema>(&self, key: &S::Key, value: &S::Value) -> Result<()>
Writes single record.
sourcepub fn range_delete<S, SK>(&self, begin: &SK, end: &SK) -> Result<()>where
S: Schema,
SK: SeekKeyCodec<S>,
pub fn range_delete<S, SK>(&self, begin: &SK, end: &SK) -> Result<()>where S: Schema, SK: SeekKeyCodec<S>,
Delete all keys in range [begin, end).
SK
has to be an explicit type parameter since
https://github.com/rust-lang/rust/issues/44721
sourcepub fn iter<S: Schema>(&self, opts: ReadOptions) -> Result<SchemaIterator<'_, S>>
pub fn iter<S: Schema>(&self, opts: ReadOptions) -> Result<SchemaIterator<'_, S>>
Returns a forward SchemaIterator
on a certain schema.
sourcepub fn rev_iter<S: Schema>(
&self,
opts: ReadOptions
) -> Result<SchemaIterator<'_, S>>
pub fn rev_iter<S: Schema>( &self, opts: ReadOptions ) -> Result<SchemaIterator<'_, S>>
Returns a backward SchemaIterator
on a certain schema.
sourcepub fn write_schemas(&self, batch: SchemaBatch) -> Result<()>
pub fn write_schemas(&self, batch: SchemaBatch) -> Result<()>
Writes a group of records wrapped in a SchemaBatch
.
sourcepub fn flush_all(&self) -> Result<()>
pub fn flush_all(&self) -> Result<()>
Flushes all memtable data. This is only used for testing get_approximate_sizes_cf
in unit
tests.