jsondbphp/jsondb

v1.0.0 2025-06-28 08:32 UTC

This package is auto-updated.

Last update: 2025-06-28 11:24:51 UTC


README

JsonDB

Tests Packagist Version Packagist Dependency Version Packagist License Packagist Downloads Packagist Stars

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.

๐Ÿš€ Features

  • โšก Zero-Config: No database server or setup neededโ€”just PHP and your filesystem.
  • ๐Ÿงฉ Document-Based: Each collection is a JSON file; each record is a structured JSON document.
  • ๐Ÿงช CRUD Operations: Easy-to-use API for create, read, update, and delete operations.
  • ๐Ÿ•ต๏ธโ€โ™‚๏ธ Search & Filter: Built-in query capabilities using associative arrays and conditions.
  • Coming soon
  • ๐Ÿ” JWT & Session Authentication: Secure API with optional login/auth guard.
  • ๐ŸŒ REST API Wrapper: JSON RESTful interface for HTTP clients.
  • ๐Ÿ—ƒ๏ธ Transactions & Atomic Writes: Prevents data corruption with locking mechanisms.
  • ๐Ÿ” Replication & Backup Support: Optional add-ons for syncing and restoring data.
  • ๐Ÿงฐ CLI Tools: Perform operations via command line using Symfony Console.
  • ๐Ÿง  In-memory Caching: Fast reads with optional caching for large JSON datasets.
  • ๐Ÿงพ Indexing (Planned): For quicker lookups and searches on large datasets.

๐Ÿ“ฆ Why Use JsonDB?

  • โœ… Simple: No external dependencies, DB servers, or complex setup.
  • โœ… Portable: Just include it in your projectโ€”works anywhere PHP runs.
  • โœ… Human-Readable: JSON files are easy to read, edit, version-control, and debug.
  • โœ… Great for Prototyping: Ideal for testing APIs, local apps, and building offline tools.
  • โœ… Customizable: Built in modern PHP (PHP 8.4+), uses OOP, Traits, Enums, and Interfaces.

๐Ÿ’ก Use Cases

  • ๐Ÿ”ง Rapid API Prototyping
  • ๐Ÿ—ƒ Offline Data Storage
  • ๐Ÿงช Test Mock Databases
  • ๐Ÿ›  Configuration/Settings Store
  • ๐ŸŽฎ Game Save/State Files
  • ๐ŸŒ Lightweight Backend for SPA/JS apps
  • ๐Ÿ’ป CLI Data Manipulation Tools

๐Ÿง‘โ€๐Ÿ’ป How It Works

Install

composer require jsondbphp/jsondb

Example

  • First create a folder data.
  • Create a users.json file inside of data folder.
<?php

require("vendor/autoload.php");

use Json\Database\JsonDB;

// Create DB instance
$db = new JsonDB(__DIR__ . '/data');

// Insert
$db->insert('users', [
    'name' => 'Alice',
    'email' => 'alice@example.com'
]);