|
1 | | -# 🛡️ FerrumDB |
| 1 | +# ⚡ FerrumDB |
2 | 2 |
|
3 | 3 | <p align="center"> |
4 | 4 | <img src="https://img.shields.io/badge/Rust-000000?style=for-the-badge&logo=rust&logoColor=white" /> |
| 5 | + <img src="https://img.shields.io/badge/Python-3776AB?style=for-the-badge&logo=python&logoColor=white" /> |
5 | 6 | <img src="https://img.shields.io/badge/License-MIT-green.svg?style=for-the-badge" /> |
6 | | - <img src="https://img.shields.io/badge/Version-0.1.2-blue.svg?style=for-the-badge" /> |
7 | | - <img src="https://img.shields.io/badge/Storage-Append--Only-orange?style=for-the-badge" /> |
| 7 | + <img src="https://img.shields.io/badge/AES--256-Encrypted-red?style=for-the-badge" /> |
8 | 8 | </p> |
9 | 9 |
|
10 | | ---- |
| 10 | +**FerrumDB** is a premium, zero-setup embedded document database for **Rust** and **Python**. No server. No config. No migrations. Just open a file and go. |
11 | 11 |
|
12 | | -**FerrumDB** is a premium, high-performance local key-value database built in **Rust**. Designed for developers who need a reliable, "zero-setup" structured data store that feels as fast as a cache but is as durable as a disk-backed database. |
| 12 | +--- |
13 | 13 |
|
14 | | -## 🌟 Why FerrumDB? |
| 14 | +## 🌟 Features |
15 | 15 |
|
16 | | -- ⚡ **Append-Only Architecture (AOF)**: $O(1)$ write performance. We never overwrite—we only grow. |
17 | | -- 📦 **Structured Data**: Native support for **JSON Values**. Store objects, arrays, and numbers directly. |
18 | | -- ⏳ **Time-To-Live (TTL)**: Built-in data expiration for efficient local caching. |
19 | | -- 🧹 **Background Compaction**: Automatic garbage collection to keep your storage footprint minimal. |
20 | | -- 🏗️ **Embeddable Library**: Use it as a CLI tool or import it as a high-level Rust crate. |
21 | | -- 🛡️ **Crash Resilient**: Atomic swaps and `sync_data` guarantee your data survives power loss. |
| 16 | +| | | |
| 17 | +|---|---| |
| 18 | +| ⚡ **O(1) reads & writes** | Append-only log + in-memory HashMap index | |
| 19 | +| 📄 **Native JSON** | Store any structured document natively | |
| 20 | +| 🔍 **Secondary Indexing** | Query by JSON fields via `create_index()` | |
| 21 | +| 🔐 **AES-256 Encryption** | Protect data at rest with one line of config | |
| 22 | +| ⚛️ **Atomic Transactions** | All-or-nothing batch operations | |
| 23 | +| 🖥️ **Ferrum Studio** | Embedded web dashboard at `localhost:7474` | |
| 24 | +| 🐍 **Python Bindings** | `pip install ferrumdb` — no Rust required | |
| 25 | +| 🛡️ **Crash Resilient** | `fsync` + atomic rename guarantee durability | |
22 | 26 |
|
23 | 27 | --- |
24 | 28 |
|
25 | | -## 🚀 Quick Start |
| 29 | +## 🐍 Python Usage |
| 30 | + |
| 31 | +```bash |
| 32 | +pip install ferrumdb |
| 33 | +``` |
| 34 | + |
| 35 | +```python |
| 36 | +from ferrumdb import FerrumDB |
| 37 | + |
| 38 | +# Zero-setup: creates myapp.db if it doesn't exist |
| 39 | +db = FerrumDB.open("myapp.db") |
| 40 | + |
| 41 | +# Store any JSON-serializable value |
| 42 | +db.set("user:1", '{"name": "alice", "role": "admin", "score": 99}') |
| 43 | +db.set("user:2", '{"name": "bob", "role": "user", "score": 45}') |
26 | 44 |
|
27 | | -### Library Usage (Zero-Setup) |
| 45 | +# Read back |
| 46 | +print(db.get("user:1")) # {"name": "alice", "role": "admin", "score": 99} |
| 47 | +print(db.count()) # 2 |
| 48 | +print(db.keys()) # ["user:1", "user:2"] |
28 | 49 |
|
29 | | -Add FerrumDB to your project and start storing data in seconds: |
| 50 | +# Secondary indexing — O(1) field lookups |
| 51 | +db.create_index("role") |
| 52 | +admins = db.find("role", '"admin"') # => ["user:1"] |
| 53 | + |
| 54 | +# Delete |
| 55 | +db.delete("user:2") |
| 56 | +``` |
| 57 | + |
| 58 | +Your data is stored in a plain file in your project directory — portable, no server, no Docker. |
| 59 | + |
| 60 | +--- |
| 61 | + |
| 62 | +## 🦀 Rust Usage |
| 63 | + |
| 64 | +```toml |
| 65 | +# Cargo.toml |
| 66 | +[dependencies] |
| 67 | +ferrumdb = "0.1.0" |
| 68 | +tokio = { version = "1", features = ["full"] } |
| 69 | +serde_json = "1" |
| 70 | +``` |
30 | 71 |
|
31 | 72 | ```rust |
32 | | -use ferrumdb::FerrumDB; |
| 73 | +use ferrumdb::{FerrumDB, Config, Transaction}; |
33 | 74 | use serde_json::json; |
34 | 75 |
|
35 | 76 | #[tokio::main] |
36 | 77 | async fn main() -> Result<(), Box<dyn std::error::Error>> { |
37 | | - // Zero-setup open (defaults to ./ferrum.db) |
| 78 | + // Standard open |
38 | 79 | let db = FerrumDB::open_default().await?; |
39 | 80 |
|
40 | | - // Store structured JSON |
41 | | - db.set("user:1".into(), json!({ |
42 | | - "name": "Usman", |
43 | | - "role": "Premium Developer" |
44 | | - })).await?; |
| 81 | + // Store documents |
| 82 | + db.set("user:1".into(), json!({"name": "alice", "role": "admin"})).await?; |
| 83 | + |
| 84 | + // Query |
| 85 | + db.create_index("role").await?; |
| 86 | + let admins = db.find("role", &json!("admin")).await; |
45 | 87 |
|
46 | | - // Retrieve data |
47 | | - if let Some(user) = db.get("user:1").await { |
48 | | - println!("User: {}", user["name"]); |
49 | | - } |
| 88 | + // Atomic transaction |
| 89 | + let tx = Transaction::new() |
| 90 | + .set("k1".into(), json!({"tag": "blue"})) |
| 91 | + .set("k2".into(), json!({"tag": "red"})) |
| 92 | + .delete("k1".into()); |
| 93 | + db.commit(tx).await?; |
| 94 | + |
| 95 | + // Encrypted database |
| 96 | + let key: [u8; 32] = *b"my_super_secret_key_32_bytes_!!"; |
| 97 | + let db_enc = FerrumDB::open( |
| 98 | + Config::new().with_encryption(key) |
| 99 | + ).await?; |
50 | 100 |
|
51 | 101 | Ok(()) |
52 | 102 | } |
53 | 103 | ``` |
54 | 104 |
|
55 | | -### CLI Interactive REPL |
| 105 | +--- |
56 | 106 |
|
57 | | -Experience the premium terminal interface with autocomplete and syntax highlighting: |
| 107 | +## 🔥 Ferrum Studio |
| 108 | + |
| 109 | +When you run the REPL, Ferrum Studio auto-launches — a premium web dashboard to browse, query, and edit your database visually. |
58 | 110 |
|
59 | 111 | ```bash |
60 | 112 | cargo run --release |
| 113 | +# 🔥 Ferrum Studio → http://localhost:7474 |
61 | 114 | ``` |
62 | 115 |
|
63 | 116 | --- |
64 | 117 |
|
65 | | -## 🛠️ Commands Reference |
66 | | - |
67 | | -| Command | Usage | Description | |
68 | | -| :--- | :--- | :--- | |
69 | | -| **SET** | `SET <key> <json>` | Store structured data (Strings, Objects, Arrays) | |
70 | | -| **GET** | `GET <key>` | Retrieve and pretty-print stored data | |
71 | | -| **DELETE** | `DELETE <key>` | Remove a key-value pair | |
72 | | -| **KEYS** | `KEYS` | List all indexed keys | |
73 | | -| **COUNT** | `COUNT` | Show total number of entries | |
74 | | -| **COMPACT**| `COMPACT` | Manually trigger log file optimization | |
75 | | -| **HELP** | `HELP` | Show commands and session metrics | |
76 | | - |
77 | | ---- |
| 118 | +## 🖥️ CLI REPL Commands |
78 | 119 |
|
79 | | -## 🎨 Premium REPL Features |
| 120 | +```bash |
| 121 | +cargo run |
| 122 | +``` |
80 | 123 |
|
81 | | -- **Tab-Complete**: Instantly complete commands and keys. |
82 | | -- **Colorized Output**: High-contrast, easy-to-read terminal feedback. |
83 | | -- **JSON Pretty-Print**: Structured output for complex data. |
| 124 | +| Command | Description | |
| 125 | +|---|---| |
| 126 | +| `SET <key> <json>` | Store a document | |
| 127 | +| `GET <key>` | Retrieve and pretty-print | |
| 128 | +| `DELETE <key>` | Remove a key | |
| 129 | +| `KEYS` | List all keys | |
| 130 | +| `COUNT` | Total number of entries | |
| 131 | +| `INDEX <field>` | Create secondary index | |
| 132 | +| `FIND <field> <value>` | Query by indexed field | |
| 133 | +| `HELP` | Show commands + session metrics | |
84 | 134 |
|
85 | 135 | --- |
86 | 136 |
|
87 | | -## 📐 Architecture |
| 137 | +## 🏗️ Architecture |
88 | 138 |
|
89 | | -- **Engine**: Bitcask-lite inspired log-structured storage. |
90 | | -- **Index**: In-memory `HashMap` leveraging `tokio::sync::RwLock` for high concurrency. |
91 | | -- **Persistence**: Binary serialization via `bincode` for maximum speed and minimal disk usage. |
| 139 | +- **Storage**: Bitcask-inspired append-only log (AOF) |
| 140 | +- **Index**: In-memory `HashMap` with `tokio::sync::RwLock` |
| 141 | +- **Encryption**: AES-256-GCM per-block, transparent decorator pattern |
| 142 | +- **Compaction**: Atomic log rewrite via temp-file + rename |
92 | 143 |
|
93 | 144 | --- |
94 | 145 |
|
95 | 146 | ## 📝 License |
96 | 147 |
|
97 | | -Distributed under the **MIT License**. See `LICENSE` for more information. |
| 148 | +MIT — see `LICENSE` for details. |
98 | 149 |
|
99 | | ---- |
100 | | - |
101 | | -<p align="center"> |
102 | | - Built with 🦀 by Muhammad Usman |
103 | | -</p> |
| 150 | +<p align="center">Built with 🦀 by Muhammad Usman</p> |
0 commit comments