datastack

Crates.iodatastack
lib.rsdatastack
version0.4.0
created_at2025-03-12 14:58:36.314108+00
updated_at2026-01-16 10:41:57.901054+00
descriptionA document-based acid local database.
homepage
repositoryhttps://github.com/focusboon/datastack.git
max_upload_size
id1589865
size30,364
focusboon (focusboon)

documentation

README

DataStack

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.


✨ Features

  • Zero Network Latency — in-process storage with no TCP/HTTP overhead
  • 📦 JSON-native via serde_json
  • 📂 Collection & subcollection support (users:u1:inbox)
  • Increment, field removal, and array manipulation helpers
  • 🔍 Prefix-optimized scanning (scan, batch_get)
  • 🛠 Dot-notation support for deep nested updates

📦 Installation

Add to your Cargo.toml:

[dependencies]
datastack = "0.4.0"

⚡ Quick Start

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?;

📂 Collections & Subcollections

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?;

🔄 Atomic Helpers & Dot Notation

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?;

Increment

db.update("users", "u1", &json!({
    "balance": increment(25)
})).await?;

db.update("users", "u1", &json!({
    "profile.points": increment(5)
})).await?;

Remove Fields

db.update("users", "u1", &json!({
    "role": remove()
})).await?;

Array Operations

db.update("users", "u1", &json!({
    "tags": array_union(json!(["rust", "db"]))
})).await?;

db.update("users", "u1", &json!({
    "tags": array_remove(json!(["rust"]))
})).await?;

🔍 Batching & Scanning

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?;

📝 Design Notes

  • Embedded, in-process storage
  • Optimized prefix-based collections
  • Acid document updates
  • Async and thread-safe
  • Dot-notation for deep JSON updates

📜 License

MIT OR Apache-2.0

Commit count: 0

cargo fmt