| Crates.io | stupid-simple-kv |
| lib.rs | stupid-simple-kv |
| version | 0.3.3 |
| created_at | 2025-05-04 09:49:13.169144+00 |
| updated_at | 2025-05-27 13:52:35.285676+00 |
| description | A dead-simple, pluggable, binary-sorted key-value store for Rust with FoundationDB-style keys. In-memory and SQLite backends. Zero-boilerplate and easy iteration. |
| homepage | https://github.com/xyzshantaram/stupid-simple-kv |
| repository | https://github.com/xyzshantaram/stupid-simple-kv |
| max_upload_size | |
| id | 1659508 |
| size | 78,963 |
A dead-simple, pluggable, and binary-sorted key-value store for Rust.
KvValue using serde_json.cargo add stupid-simple-kv
use stupid_simple_kv::{Kv, MemoryBackend, KvValue};
let backend = Box::new(MemoryBackend::new());
let mut kv = Kv::new(backend);
let key = (42u64, "foo").to_key();
// automatically convert compatible value types to KvValue
kv.set(&key, "value".into())?;
let out = kv.get(&key)?;
assert_eq!(out, Some(String::from("value").into()));
kv.delete(&key)?;
let backend = Box::new(MemoryBackend::new());
let mut kv = Kv::new(backend);
for id in 0..5 {
let key = (1u64, id).to_key();
kv.set(&key, id.into())?;
}
// List all values with prefix (1, _)
let results = kv.list().prefix(&(1u64,)).entries()?; // Vec<(KvKey, KvValue)>
Just implement IntoKey for your type:
use stupid_simple_kv::IntoKey;
struct UserKey {
namespace: String,
id: u64,
}
impl IntoKey for UserKey {
fn to_key(&self) -> stupid_simple_kv::KvKey {
(&self.namespace, self.id).to_key()
}
}
Note: You can choose to not use the SQLite backend by disabling the sqlite
feature.
use stupid_simple_kv::{Kv, SqliteBackend};
let backend = Box::new(SqliteBackend::in_memory()?);
let mut kv = Kv::new(backend);
let key = ("foo",).to_key();
kv.set(&key, "bar".into())?;
kv.dump_json().Kv::from_json_string(...).Example:
let json = kv.dump_json()?;
// ...
let backend = Box::new(MemoryBackend::new());
let mut loaded = Kv::from_json_string(backend, json)?;
MIT License © 2025 Siddharth S Singh (me@shantaram.xyz)