| Crates.io | datastack |
| lib.rs | datastack |
| version | 0.4.0 |
| created_at | 2025-03-12 14:58:36.314108+00 |
| updated_at | 2026-01-16 10:41:57.901054+00 |
| description | A document-based acid local database. |
| homepage | |
| repository | https://github.com/focusboon/datastack.git |
| max_upload_size | |
| id | 1589865 |
| size | 30,364 |
DataStack is a high-performance, async-first embedded document database for Rust.
It provides Firestore-style collections, JSON-native updates, and zero-latency local storage by running in-process with your application.
serde_jsonusers:u1:inbox)scan, batch_get)Add to your Cargo.toml:
[dependencies]
datastack = "0.4.0"
use datastack::{DataStack, json};
let db = DataStack::new("./storage/local_db").await?;
let user = json!({
"id": "u1",
"name": "Alice",
"age": 25
});
db.add("users", "u1", &user).await?;
let fetched = db.get("users", "u1").await?.unwrap();
println!("Fetched: {:?}", fetched);
db.update("users", "u1", &json!({
"age": 26,
"active": true
})).await?;
db.delete("users", "u1").await?;
db.add("users:u1:inbox", "m1", &json!({
"title": "Hello",
"body": "First message"
})).await?;
let msg = db.get("users:u1:inbox", "m1").await?.unwrap();
db.add("users:u1:inbox:group1", "g1msg", &json!({
"title": "Group message"
})).await?;
use datastack::{
DataStack, json,
increment, remove,
array_union, array_remove
};
let db = DataStack::new("./storage/local_db").await?;
db.add("users", "u1", &json!({
"balance": 100,
"profile": { "points": 10 }
})).await?;
db.update("users", "u1", &json!({
"balance": increment(25)
})).await?;
db.update("users", "u1", &json!({
"profile.points": increment(5)
})).await?;
db.update("users", "u1", &json!({
"role": remove()
})).await?;
db.update("users", "u1", &json!({
"tags": array_union(json!(["rust", "db"]))
})).await?;
db.update("users", "u1", &json!({
"tags": array_remove(json!(["rust"]))
})).await?;
let batch_docs = json!({
"tx1": { "amount": 100, "type": "send" },
"tx2": { "amount": 200, "type": "receive" }
});
db.batch_add("transactions:u123", &batch_docs).await?;
let scanned = db.scan("users", 10, "", "a").await?;
let ids = json!(["tx1", "tx2"]);
let docs = db.batch_get("transactions:u123", &ids).await?;
db.batch_delete("transactions:u123", &ids).await?;
MIT OR Apache-2.0