Crates.io | mu_db |
lib.rs | mu_db |
version | 0.0.1 |
source | src |
created_at | 2024-03-23 19:17:46.810452 |
updated_at | 2024-03-23 19:17:46.810452 |
description | A simple and lightweight key-value based database |
homepage | |
repository | https://github.com/ManiGhazaee/mu_db |
max_upload_size | |
id | 1183748 |
size | 23,442 |
let mut db = mu_db::DataBase::new("./test.db");
// This will generate ./test.db and ./index_test.db if they don't exist.
db.insert("key", "before_value");
db.insert("key", "after_value");
let value = db.get("key");
assert_eq!(value, Some("after_value".to_string()));
db.remove("key");
assert_eq!(db.get("key"), None);
assert!(db.is_empty()); // index is empty
assert!(!db.is_buf_empty()); // db is not empty
assert_eq!(db.buf_len(), 12); // db: `after_valuee`
db.shrink(); // remove unused space
assert!(db.is_buf_empty());
db.write_at(5, "world").unwrap(); // write to db file directly without syncing index
let data = db.read_at(5, 5).unwrap(); // read db file directly
assert_eq!(data, "world".to_string());
db.clear_all().unwrap(); // clear everything (index and db)
assert!(db.is_empty());
assert!(db.is_buf_empty());
Please note that the mu_db is a simple, lightweight database and does not support complex database operations like transactions, joins, etc. It is best suited for simple key-value storage needs.