Skip to content

Commit

Permalink
feat: setup a lightweight performance db
Browse files Browse the repository at this point in the history
  • Loading branch information
mubarak23 committed Oct 9, 2024
1 parent dfa666c commit 83d03d3
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/db.rs
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)
}
}

0 comments on commit 83d03d3

Please sign in to comment.