pub struct GrausDb { /* private fields */ }Expand description
The GrausDb stores string key/value pairs.
Key/value pairs are persisted to disk in log files. Log files are named after
monotonically increasing generation numbers with a log extension name.
A SkipMap in memory stores the keys and the value locations for fast query.
GrausDb is thead-safe. It can be cloned to use it on new threads.
use std::env::current_dir;
let store = GrausDb::open(current_dir()?)?;
store.set(b"key".to_vec(), b"value")?;
let val = store.get(b"key")?;
assert_eq!(val, Some(b"value".to_vec()));Implementations§
Source§impl GrausDb
impl GrausDb
Sourcepub fn open(path: impl Into<PathBuf>) -> Result<GrausDb>
pub fn open(path: impl Into<PathBuf>) -> Result<GrausDb>
Opens a GrausDb with the given path.
This will create a new directory if the given one does not exist.
§Errors
It propagates I/O or deserialization errors during the log replay.
Sourcepub fn set(&self, key: Vec<u8>, value: &[u8]) -> Result<()>
pub fn set(&self, key: Vec<u8>, value: &[u8]) -> Result<()>
Sets the value of a string key to a string.
If the key already exists, the previous value will be overwritten.
Sourcepub fn get(&self, key: &[u8]) -> Result<Option<Vec<u8>>>
pub fn get(&self, key: &[u8]) -> Result<Option<Vec<u8>>>
Gets the string value of a given string key.
Returns None if the given key does not exist.
Sourcepub fn remove(&self, key: &[u8]) -> Result<()>
pub fn remove(&self, key: &[u8]) -> Result<()>
Removes a given key.
Returns GrausError::KeyNotFound if the key does not exist.