datastack 0.4.0

A document-based acid local database.
Documentation
# 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`:

```toml
[dependencies]
datastack = "0.4.0"
```

---

## ⚡ Quick Start

```rust
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

```rust
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

```rust
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

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

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

### Remove Fields

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

### Array Operations

```rust
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

```rust
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