OsunbitDB
OsunbitDB is a lightweight, async-first key-value database for Rust, built on TiKV.
It supports Firestore-style collections, JSON-friendly updates, and atomic transactions.
✨ Features
- 📦 Built on top tikv super fast atomic transaction client
- 🚀 Async-first with tokio
- 📦 JSON-native via
serde_json - 📂 Collection & subcollection support (
users:u1:inbox) - 🔄 Atomic transactions
- ➕ Increment & field removal helpers
- 🔍 Simple API (
add,get,update,delete,scan)
📦 Installation
Add to Cargo.toml:
[]
= "0.7.0"
⚡ Quick Start
use ;
// Connect to the tikv cluster
let db = new.await?;
// ➕ Add a document
let user = json!;
db.add.await?;
// 🔍 Get a document
let fetched = db.get.await?.unwrap;
println!;
// ✏️ Update fields (partial update, other fields untouched or create if not exists)
db.update.await?;
// ❌ Delete document
db.delete.await?;
📂 Collections & Subcollections
// Add to a subcollection
db.add.await?;
// Fetch
let msg = db.get.await?.unwrap;
println!;
// Nested sub-subcollection
db.add.await?;
🔄 Increment & Remove & Array Union & Array Remove & ExpiryAt Helpers
use ;
let db = new.await?;
db.add.await?;
// ➕ Increment field
db.update.await?;
// balance = 125
// ➖ Decrement field
db.update.await?;
// balance = 120
// 🗑️ Remove a field (top-level)
db.update.await?;
// ➕ Increment nested field
db.update.await?;
// profile.points = 15
// 🗑️ Remove nested field
db.update.await?;
// 🔗 Array Union (top-level)
db.update.await?;
// ✅ Array array_remove (top-level)
db.update.await?;
// ✅ ExpiryAt test
let exp_doc = json!;
db.update.await?;
🔒 Transactions (Atomic Ops)
use ;
// Start a transaction
let mut tx = db.transaction.await?;
// Atomic balance transfer
tx.update.await?;
tx.update.await?;
// Add a notification
tx.add.await?;
// Commit all changes
tx.commit.await?;
// Rollback example
let mut tx2 = db.transaction.await?;
tx2.update.await?;
tx2.rollback.await?;
🔍 Scanning Collections
// scan first 10
// "a" for ascending order & "d" for descending order
let scanned = db.scan.await?;
// scan 10 from id
let scanned_from_id = db.scan.await?;
let batch_docs = json!;
db.batch_add.await?;
let ids_json = json!;
let docs = db.batch_get.await?;
let ids_to_delete = json!;
db.batch_delete.await?;
📝 Notes
- Collections are just logical namespaces (
users,users:u1:inbox) - Subcollections can be nested infinitely using
: - Updates only modify provided fields (others remain unchanged)
- All operation are transaction
- Transactions guarantee all-or-nothing execution
- All helpers support dot notation for nested fields
- increment() works with positive or negative numbers.
- remove() deletes the field entirely.
- array_union() merges arrays without duplicates.
📜 License
MIT OR Apache-2.0