-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: setup a lightweight performance db
- Loading branch information
Showing
1 changed file
with
30 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
use sled::Db; | ||
|
||
pub struct Database { | ||
db: Db | ||
}; | ||
|
||
impl Database { | ||
pub fn new (path: &str) -> Self { | ||
let db = sled::open(path).expect("Failed to open database"); | ||
Database { | ||
db | ||
} | ||
} | ||
|
||
pub fn insert(&self, key: &str, value: &[u8]) { | ||
self.db.insert(key.as_bytes(), value).expect("Fail to write tot DB") | ||
} | ||
|
||
pub fn put(&self) { | ||
self.db.insert(key.as_bytes(), value).expect("Failed to write to database"); | ||
} | ||
|
||
pub fn get(&self, key = &str) -> Option<Vec<u8>> { | ||
self.db.get(key.as_bytes) | ||
} | ||
|
||
pub fn delete(&self, key = &str) { | ||
self.db.remove(key) | ||
} | ||
} |