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("key".to_owned(), "value".to_owned())?;
let val = store.get("key".to_owned())?;
assert_eq!(val, Some("value".to_owned()));
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: String, value: String) -> Result<()>
pub fn set(&self, key: String, value: String) -> 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: String) -> Result<Option<String>>
pub fn get(&self, key: String) -> Result<Option<String>>
Gets the string value of a given string key.
Returns None
if the given key does not exist.
Sourcepub fn remove(&self, key: String) -> Result<()>
pub fn remove(&self, key: String) -> Result<()>
Removes a given key.
Returns GrausError::KeyNotFound if the key does not exist.