|
| 1 | +**JsonDB:** Lightweight Document Container for Modern PHP Apps. |
| 2 | + |
1 | 3 | 
|
2 | 4 |
|
3 | 5 | [](https://github.com/CodeWithSushil/json-db/actions/workflows/tests.yml)
|
| 6 | + |
| 7 | + |
| 8 | + |
| 9 | + |
| 10 | + |
| 11 | + |
| 12 | + |
| 13 | +**JsonDB** is a lightweight, document-oriented NoSQL-style database written in PHP. It provides a simple, file-based alternative to traditional databases by storing and managing data as structured JSON files. JsonDB is perfect for lightweight apps, prototyping, local storage, and embedded tools where a full-fledged database system is unnecessary. |
| 14 | + |
| 15 | +--- |
| 16 | + |
| 17 | +## 🚀 Features |
| 18 | + |
| 19 | +- ⚡ **Zero-Config:** No database server or setup needed—just PHP and your filesystem. |
| 20 | +- 🧩 **Document-Based:** Each collection is a JSON file; each record is a structured JSON document. |
| 21 | +- 🧪 **CRUD Operations:** Easy-to-use API for create, read, update, and delete operations. |
| 22 | +- 🕵️♂️ **Search & Filter:** Built-in query capabilities using associative arrays and conditions. |
| 23 | +- 🔐 **JWT & Session Authentication:** Secure API with optional login/auth guard. |
| 24 | +- 🌐 **REST API Wrapper:** JSON RESTful interface for HTTP clients. |
| 25 | +- 🗃️ **Transactions & Atomic Writes:** Prevents data corruption with locking mechanisms. |
| 26 | +- 🔁 **Replication & Backup Support:** Optional add-ons for syncing and restoring data. |
| 27 | +- 🧰 **CLI Tools:** Perform operations via command line using Symfony Console. |
| 28 | +- 🧠 **In-memory Caching:** Fast reads with optional caching for large JSON datasets. |
| 29 | +- 🧾 **Indexing (Planned):** For quicker lookups and searches on large datasets. |
| 30 | + |
| 31 | +--- |
| 32 | + |
| 33 | +## 📦 Why Use JsonDB? |
| 34 | + |
| 35 | +- ✅ **Simple:** No external dependencies, DB servers, or complex setup. |
| 36 | +- ✅ **Portable:** Just include it in your project—works anywhere PHP runs. |
| 37 | +- ✅ **Human-Readable:** JSON files are easy to read, edit, version-control, and debug. |
| 38 | +- ✅ **Great for Prototyping:** Ideal for testing APIs, local apps, and building offline tools. |
| 39 | +- ✅ **Customizable:** Built in modern PHP (PHP 8.4+), uses OOP, Traits, Enums, and Interfaces. |
| 40 | + |
| 41 | +--- |
| 42 | + |
| 43 | +## 💡 Use Cases |
| 44 | + |
| 45 | +- 🔧 Rapid API Prototyping |
| 46 | +- 🗃 Offline Data Storage |
| 47 | +- 🧪 Test Mock Databases |
| 48 | +- 🛠 Configuration/Settings Store |
| 49 | +- 🎮 Game Save/State Files |
| 50 | +- 🌐 Lightweight Backend for SPA/JS apps |
| 51 | +- 💻 CLI Data Manipulation Tools |
| 52 | + |
| 53 | +--- |
| 54 | + |
| 55 | +## 🧑💻 How It Works |
| 56 | + |
| 57 | +```php |
| 58 | +use JsonDB\JsonDB; |
| 59 | + |
| 60 | +// Create DB instance |
| 61 | +$db = new JsonDB(__DIR__ . '/data'); |
| 62 | + |
| 63 | +// Insert |
| 64 | +$id = $db->collection('users')->insert([ |
| 65 | + 'name' => 'Alice', |
| 66 | + 'email' => 'alice@example.com' |
| 67 | +]); |
| 68 | + |
| 69 | +// Find |
| 70 | +$user = $db->collection('users')->find($id); |
| 71 | + |
| 72 | +// Update |
| 73 | +$db->collection('users')->update($id, ['email' => 'new@example.com']); |
| 74 | + |
| 75 | +// Delete |
| 76 | +$db->collection('users')->delete($id); |
| 77 | +``` |
| 78 | + |
| 79 | +--- |
4 | 80 |
|
5 |
| -JsonDB: Lightweight document container. |
| 81 | +## Install |
6 | 82 |
|
7 |
| -___ |
| 83 | +```bash |
| 84 | +composer require jsondbphp/jsondb |
| 85 | +``` |
0 commit comments