Crates.io | siamesedb |
lib.rs | siamesedb |
version | 0.1.23 |
source | src |
created_at | 2021-10-30 06:22:49.483298 |
updated_at | 2024-06-18 19:48:22.015657 |
description | The simple local key-value store. |
homepage | |
repository | https://github.com/aki-akaguma/siamesedb |
max_upload_size | |
id | 474290 |
size | 568,290 |
The simple local key-value store.
DbMapDbString
has keys as utf-8 string.DbMapDbInt
has keys as u64.DbMapDbBytes
has keys as Vecuse siamesedb::{DbMapDbString, DbXxx, DbXxxBase, DbXxxObjectSafe};
fn main() -> std::io::Result<()> {
let db_name = "target/tmp/doc-test1.siamesedb";
// remove database
let _ = std::fs::remove_dir_all(db_name);
// create or open database
let db = siamesedb::open_file(db_name)?;
// create or get db map
let mut db_map = db.db_map_string("some_map1")?;
//
let r = db_map.get_string("key1")?;
assert_eq!(r, None);
db_map.put_string("key1", "value1")?;
let r = db_map.get_string("key1")?;
assert_eq!(r, Some("value1".into()));
db_map.sync_data()?;
Ok(())
}
use siamesedb::{DbMapDbInt, DbXxx, DbXxxBase, DbXxxObjectSafe};
fn main() -> std::io::Result<()> {
let db_name = "target/tmp/doc-test2.siamesedb";
// remove database
let _ = std::fs::remove_dir_all(db_name);
// create or open database
let db = siamesedb::open_file(db_name)?;
let mut db_map = db.db_map_int("some_list1")?;
let r = db_map.get_string(&120)?;
assert_eq!(r, None);
db_map.put_string(&120, "value120")?;
let r = db_map.get_string(&120)?;
assert_eq!(r, Some("value120".to_string()));
db_map.sync_data()?;
Ok(())
}
use siamesedb::{DbMapDbString, DbMap, DbXxx, DbXxxBase, DbXxxObjectSafe};
fn main() -> std::io::Result<()> {
let db_name = "target/tmp/doc-test3.siamesedb";
// remove database
let _ = std::fs::remove_dir_all(db_name);
// create or open database
let db = siamesedb::open_file(db_name)?;
// create or get db map
let mut db_map = db.db_map_string("some_map1")?;
//
// insert
db_map.put_string("key01", "value1").unwrap();
db_map.put_string("key02", "value2").unwrap();
db_map.put_string("key03", "value3").unwrap();
//
// iterator
let mut iter = db_map.iter();
assert_eq!(iter.next(), Some(("key01".into(), "value1".into())));
assert_eq!(iter.next(), Some(("key02".into(), "value2".into())));
assert_eq!(iter.next(), Some(("key03".into(), "value3".into())));
assert_eq!(iter.next(), None);
//
db_map.sync_data()?;
Ok(())
}
This project is licensed under either of
at your option.