pub struct DB { /* private fields */ }
Expand description
This struct represents an open instance of the database.
Implementations§
Source§impl DB
impl DB
Sourcepub fn open(path: &Path) -> LevelDBResult<DB>
pub fn open(path: &Path) -> LevelDBResult<DB>
Open a database at the given path. Returns a Result indicating whether the database could be opened. Note that this function will not create the database at the given location if it does not exist.
Sourcepub fn create(path: &Path) -> LevelDBResult<DB>
pub fn create(path: &Path) -> LevelDBResult<DB>
Create and returns a database at the given path.
Sourcepub fn open_with_opts(path: &Path, opts: DBOptions) -> LevelDBResult<DB>
pub fn open_with_opts(path: &Path, opts: DBOptions) -> LevelDBResult<DB>
Open a database at the given path, using the provided options to control the open behaviour. Returns a Result indicating whether or not the database could be opened.
Sourcepub fn put(&mut self, key: &[u8], val: &[u8]) -> LevelDBResult<()>
pub fn put(&mut self, key: &[u8], val: &[u8]) -> LevelDBResult<()>
Set the database entry for “key” to “value”. Returns a result indicating the success or failure of the operation.
Sourcepub fn put_opts(
&mut self,
key: &[u8],
val: &[u8],
opts: DBWriteOptions,
) -> LevelDBResult<()>
pub fn put_opts( &mut self, key: &[u8], val: &[u8], opts: DBWriteOptions, ) -> LevelDBResult<()>
Set the database entry for “key” to “value”. Allows specifying the write options to use for this operaton.
Sourcepub fn delete(&mut self, key: &[u8]) -> LevelDBResult<()>
pub fn delete(&mut self, key: &[u8]) -> LevelDBResult<()>
Remove the database entry (if any) for “key”. Returns a result indicating the success of the operation. It is not an error if “key” did not exist in the database.
Sourcepub fn delete_opts(
&mut self,
key: &[u8],
opts: DBWriteOptions,
) -> LevelDBResult<()>
pub fn delete_opts( &mut self, key: &[u8], opts: DBWriteOptions, ) -> LevelDBResult<()>
Remove the database entry (if any) for “key”. As delete()
, but allows
specifying the write options to use for this operation.
Sourcepub fn write(&mut self, batch: DBWriteBatch) -> LevelDBResult<()>
pub fn write(&mut self, batch: DBWriteBatch) -> LevelDBResult<()>
Apply the specified updates to the database, as given in the provided DBWriteBatch. Returns a result indicating the success of the operation.
Sourcepub fn write_opts(
&mut self,
batch: DBWriteBatch,
opts: DBWriteOptions,
) -> LevelDBResult<()>
pub fn write_opts( &mut self, batch: DBWriteBatch, opts: DBWriteOptions, ) -> LevelDBResult<()>
Apply the given write batch. As write()
, but allows specifying the
write options to use for this operation.
Sourcepub fn get(&self, key: &[u8]) -> LevelDBResult<Option<Vec<u8>>>
pub fn get(&self, key: &[u8]) -> LevelDBResult<Option<Vec<u8>>>
If the database contains an entry for “key”, return the associated value
- otherwise, return None. This value is wrapped in a Result to indicate if an error occurred.
Sourcepub fn get_opts(
&self,
key: &[u8],
opts: DBReadOptions,
) -> LevelDBResult<Option<Vec<u8>>>
pub fn get_opts( &self, key: &[u8], opts: DBReadOptions, ) -> LevelDBResult<Option<Vec<u8>>>
Get the value for a given key. As get()
, but allows specifying the
options to use when reading.
Sourcepub fn iter(&mut self) -> LevelDBResult<DBIterator>
pub fn iter(&mut self) -> LevelDBResult<DBIterator>
Return an iterator over the database.
Sourcepub fn snapshot(&self) -> DBSnapshot
pub fn snapshot(&self) -> DBSnapshot
Return a snapshot of the database.