{"id":23099343,"url":"https://github.com/mohamed-samir907/jldb","last_synced_at":"2025-08-16T13:30:59.426Z","repository":{"id":62539822,"uuid":"232873829","full_name":"mohamed-samir907/JLDB","owner":"mohamed-samir907","description":"Simple and powerfull tool that allows to use json file like a database. It provides collection of methods that you can use like a database query builder.","archived":false,"fork":false,"pushed_at":"2020-01-12T17:53:21.000Z","size":32,"stargazers_count":48,"open_issues_count":0,"forks_count":6,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-04-20T14:34:46.991Z","etag":null,"topics":["jldb","json","json-db","json-lite","json-lite-database","php7"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mohamed-samir907.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-01-09T18:09:28.000Z","updated_at":"2022-10-14T21:42:34.000Z","dependencies_parsed_at":"2022-11-02T15:46:04.863Z","dependency_job_id":null,"html_url":"https://github.com/mohamed-samir907/JLDB","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mohamed-samir907%2FJLDB","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mohamed-samir907%2FJLDB/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mohamed-samir907%2FJLDB/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mohamed-samir907%2FJLDB/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mohamed-samir907","download_url":"https://codeload.github.com/mohamed-samir907/JLDB/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230038879,"owners_count":18163324,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["jldb","json","json-db","json-lite","json-lite-database","php7"],"created_at":"2024-12-16T23:18:56.797Z","updated_at":"2024-12-16T23:18:57.273Z","avatar_url":"https://github.com/mohamed-samir907.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\u003cimg src=\"https://repository-images.githubusercontent.com/232873829/e2c45600-33b0-11ea-941f-ba319f2d3c52\" width=\"500\"/\u003e\u003c/p\u003e\n\u003cp align=\"center\"\u003e\n\u003ca href=\"https://github.styleci.io/repos/232873829\"\u003e\u003cimg src=\"https://github.styleci.io/repos/232873829/shield?branch=master\" /\u003e\u003c/a\u003e\n\u003ca href=\"https://packagist.org/packages/samirzz/jldb\"\u003e\u003cimg src=\"https://img.shields.io/packagist/php-v/samirzz/jldb?label=php\u0026style=flat-square\"/\u003e\u003c/a\u003e\n\u003ca href=\"https://packagist.org/packages/samirzz/jldb\"\u003e\u003cimg src=\"https://img.shields.io/github/contributors/mohamed-samir907/jldb?style=flat-square\"/\u003e\u003c/a\u003e\n\u003ca href=\"https://packagist.org/packages/samirzz/jldb\"\u003e\u003cimg src=\"https://img.shields.io/badge/License-MIT-blue?style=flat-square\"/\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n# PHP JLDB (JSON Lite DB)\nSimple and powerfull tool that allows to use json file like a database. It provides collection of methods that you can use like a database query builder.\n\n## Installation\n\n```json\ncomposer require samirzz/jldb\n```\n\n## Usage\n\n1. Create a config.php file like that\n\n```php\n\u003c?php\n\nreturn [\n\n    /**\n     * The default json file storage path that the user store the data on it.\n     */\n    'db_path' =\u003e __DIR__ . '/../storage',\n\n    /**\n     * Database name (json file name)\n     */\n    'db_name' =\u003e 'default.json'\n];\n\n```\n\n2. include config file in your project and create new object from the class like that\n\n```php\n\u003c?php\n// index.php\nrequire __DIR__ . '/vendor/autoload.php';\n\nuse Samirzz\\JsonDB\\JsonDB;\n\n$config = include __DIR__ . '/config/jsondb.php';\n\n$db = new JsonDB($config);\n\n\n```\n\nNow, you can use the method like that\n\n```php\n// index.php\n\n/**\n * NOTE:\n * When you write the name of the table, if the table\n * not exists we will create it for you.\n * So don't worry about the creation of the table.\n */\n\n/*\n | Create Record on the table\n |\n */\n\n$data = [\n    \"name\" =\u003e \"Mohamed Samir\",\n    \"email\" =\u003e \"gm.mohamedsamir@gmail.com\",\n    \"github\" =\u003e \"mohamed-samir907\"\n];\n\n// This will create record on users table \n// If the data array doesn't has a primary key\n// we will add primary key on create method to the data\n// array. The default primary key is 'id' if you need\n// to change it, pass the name of primary key as second paramenter\n$users = $db-\u003etable('users')-\u003ecreate($data); // primaryKey = id\n$users = $db-\u003etable('users')-\u003ecreate($data, '_key'); //primary key = _key\n\n\n/*\n | Update an Existing Record on the table\n |\n */\n\n$data = [\n    \"name\" =\u003e \"Orange\",\n    \"quantity\" =\u003e 4,\n    \"price\" =\u003e 10,\n    \"totalPrice\" =\u003e 40\n];\n\n$products = $db-\u003etable('products')-\u003eupdate(27, $data);\n\n// if the primary key not equal to 'id' then you can pass the prmary key as the following\n$products = $db-\u003etable('products')-\u003eupdate(27, $data, '_key');\n\n/*\n | Delete an Existing Record on the table\n |\n */\n\n$db-\u003etable('users')-\u003edelete(12);\n\n// OR: in case of primary key changed\n$db-\u003etable('users')-\u003edelete(12, '_key');\n\n\n\n/*\n |      Fetch the data\n |\n */\n\n// Get all tables data\n$database = $db-\u003eall();\n\n// Get table data\n$products = $db-\u003etable('products')-\u003efind(27);\n$products = $db-\u003etable('products')-\u003efind(27, '_key');\n\n\n// Get table data\n$products = $db-\u003etable('products')-\u003eget();\n\n// Get with where\n$products = $db-\u003etable('products')\n    -\u003ewhere('name', '=', 'Orange')\n    -\u003eget();\n\n$products = $db-\u003etable('products')\n    -\u003ewhere('name', '=', 'Orange')\n    -\u003ewhere('totalPrice', '\u003e=', '10')\n    -\u003eget();\n\n// Get the records Paginated\n$products = $db-\u003etable('products')-\u003epaginate(20);\n\n// Get last record on the table\n$product = $db-\u003etable('products')-\u003elast();\n\n// Get first record on the table\n$product = $db-\u003etable('products')-\u003efirst();\n\n// Get count records on the table\n$countProducts = $db-\u003etable('products')-\u003ecount();\n\n// Get count of column=value in the table\n$countOrange = $db-\u003etable('products')-\u003ecountOf(\"name\", \"Orange\");\n\n// If you love object style you can convert the array to object like that\n// use toObject() helper function\n$users = toObject($db-\u003etable('users')-\u003eget());\n\nforeach ($users as $user) {\n    echo $user-\u003ename;\n}\n\n```\n\n## TODO\n- add join, like, take, skip, groupBy, orderBy\n- support functions like sum, avg, ... and allow the user to create his own function.\n- select(...$columns)\n- create prepare trait to check pendings and return the result of them.\n\n- change the structure\n    - create folder for each database\n    - create json file for each table\n\n- add encryption to the database\n- add username, password for connect to the database.\n- add Model for each table\n- add schema class and save the tables schema in json file related to the database it self.\n- add validation class for validate the type of the column.\n- add relationships between tables.\n\n- Add support to redis","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmohamed-samir907%2Fjldb","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmohamed-samir907%2Fjldb","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmohamed-samir907%2Fjldb/lists"}