| Crates.io | storedb |
| lib.rs | storedb |
| version | 2.0.0 |
| created_at | 2024-10-23 03:43:45.148188+00 |
| updated_at | 2024-12-13 06:08:39.000769+00 |
| description | Disk-backed transactional key-value database |
| homepage | https://github.com/aaiyer/storedb |
| repository | https://github.com/aaiyer/storedb |
| max_upload_size | |
| id | 1419643 |
| size | 41,305 |
StoreDB is a disk-backed transactional database that supports multiple named collections. Each collection is stored in a single table (kv_store) and separated by a collection column. Type metadata for each collection is stored in collection_meta.
rusqlite and postcard for serialization.use serde::{Serialize, Deserialize};
use storedb::{Database, Error};
#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone)]
struct User {
id: u32,
name: String,
}
fn main() -> Result<(), Error> {
let mut db = Database::new("example.db")?;
let mut users = db.get_collection::<u32, User>("users")?;
{
let mut tx = users.begin()?;
tx.put(1u32, User { id: 1, name: "Alice".into() })?;
tx.put(2u32, User { id: 2, name: "Bob".into() })?;
tx.commit()?;
}
let tx = users.begin()?;
if let Some(user) = tx.get(1u32)? {
println!("Retrieved User: {:?}", user);
}
let keys = tx.keys()?;
println!("All User IDs: {:?}", keys);
Ok(())
}