Provides a simple, fast, and embedded database solution, focusing on maintaining coherence between Rust types and stored data with minimal boilerplate. It supports multiple indexes, real-time watch with filters, schema migration, enjoy 😌🍃.
enum
, struct
, tuple
etc.).get
, watch
, iter
etc.) using explicit type or type inference. insert
, update
and delete
operations.Early development. Not ready for production.
See docs.rs.
```rust use serde::{Deserialize, Serialize}; use struct_db::*;
fn_primary_key(p_key), // required
fn_secondary_key(s_key), // optional
// ... other fn_secondary_key ...
)] struct Data(u32, String);
impl Data {
// Returns primary key as big-endian bytes for consistent lexicographical ordering.
pub fn pkey(&self) -> Vec
// Generates a secondary key combining the String field and the big-endian bytes of
// the primary key for versatile queries.
pub fn skey(&self) -> Vec
fn main() { let mut db = Db::inittmp("mydbexample").unwrap(); // Initialize the schema db.addschema(Data::structdbschema());
// Insert data let txn = db.transaction().unwrap(); { let mut tables = txn.tables(); tables.insert(&txn, Data(1,"red".tostring())).unwrap(); tables.insert(&txn, Data(2,"red".tostring())).unwrap(); tables.insert(&txn, Data(3,"blue".to_string())).unwrap(); } txn.commit().unwrap();
let txnread = db.readtransaction().unwrap(); let mut tables = txn_read.tables();
// Retrieve data with pkey=3 let retrievedata: Data = tables.primaryget(&txnread, &3u32.tobebytes()).unwrap().unwrap(); println!("data pkey='3' : {:?}", retrieve_data);
// Iterate data with skey="red" String for item in tables.secondaryiterstartwith::(&txnread, DataKey::skey, "red".asbytes()).unwrap() { println!("data skey='1': {:?}", item); }
// Remove data let txn = db.transaction().unwrap(); { let mut tables = txn.tables(); tables.remove(&txn, retrieve_data).unwrap(); } txn.commit().unwrap(); } ```
The following features are planned before the 1.0 release