{"id":27232076,"url":"https://github.com/garymengcom/jsondb","last_synced_at":"2025-04-10T13:55:25.151Z","repository":{"id":104605359,"uuid":"86895934","full_name":"garymengcom/JsonDb","owner":"garymengcom","description":"A class to handle json file like SQL","archived":false,"fork":false,"pushed_at":"2017-04-20T03:56:45.000Z","size":7,"stargazers_count":4,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-09T21:41:05.338Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/garymengcom.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-04-01T08:02:19.000Z","updated_at":"2022-12-23T08:25:44.000Z","dependencies_parsed_at":null,"dependency_job_id":"5718d882-f566-4142-8c07-5c32ee1abe6b","html_url":"https://github.com/garymengcom/JsonDb","commit_stats":null,"previous_names":["garymengcom/jsondb"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/garymengcom%2FJsonDb","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/garymengcom%2FJsonDb/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/garymengcom%2FJsonDb/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/garymengcom%2FJsonDb/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/garymengcom","download_url":"https://codeload.github.com/garymengcom/JsonDb/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248229606,"owners_count":21068943,"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":[],"created_at":"2025-04-10T13:55:24.423Z","updated_at":"2025-04-10T13:55:25.135Z","avatar_url":"https://github.com/garymengcom.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Profile\n**JsonDb** is a PHP class used to CRUD (`INSERT`, `UPDATE`, `SELECT`, `DELETE`) json file like SQL.\n\nIt's easy and lightweight.\n\n# Demo\n[Click Demo](http://www.awaimai.com/demo/JsonDb/example/)\n\n\n# Usage\n1. Create a directory `files` and a demo file name `demo.json` located the directory.\n2. Include JsonDb.php in your project, `new JsonDb` and identify json files directory:\n    ```\n      include 'JsonDb.php';\n      $json = new JsonDb('./files');\n    ```\n3. Then you can insert/select a record to `demo.json`:\n    ```\n      $data = ['name' =\u003e 'Gary', 'title' =\u003e 'PHP', 'website' =\u003e 'http://www.awaimai.com/'];\n\n      echo $json-\u003edemo-\u003einsert($data);        //return the inserted id\n      print_r($json-\u003edemo-\u003eselectAll());      // return all record\n\n      $json-\u003edemo-\u003edelete('*');\n    ```\nHere, property `demo` of `$json` is same as the name of json file `demo.json` (exclude extension `.json`).\n\n# User guide\n\n### 1. Setup\n\nCreate JsonDB with `$directory='./files'`, `$primary='page_id'`, and file `$extension='.js'`:\n```\n$json = new JsonDb('./files', 'page_id', '.js');\n```\n**Note:** **directory** is required, primary key default is `id`, file extension default is `'.json'`.\n\n### 2. Select\n```\n    $json-\u003edemo-\u003eselect(2);                       // Select a record which's primary key is 2\n    $json-\u003edemo-\u003eselectAll();                     // Select all records\n    $json-\u003edemo-\u003eselectAll(['sort' =\u003e 'DESC');    // Select all records ordered desc by sort\n    $json-\u003edemo-\u003eselectIn([2, 3, 5]);             // Select some records\n    $json-\u003edemo-\u003ecount();                         // Number of records\n```\n\n### 3. Insert\n```\n    $json-\u003edemo-\u003einsert(['name' =\u003e 'Gary', 'title' =\u003e 'PHP']);\n```\n\n### 4.Update\n```\n    $json-\u003edemo-\u003eupdate(['id' =\u003e 1, 'name' =\u003e 'Galley']);\n```\nThis will change the name of a record which's id is `1`, other field will not be affected.\n\n### 5. Update multiples\n```\n    $data = [\n        ['id' =\u003e 1, 'name' =\u003e 'Jack'],\n        ['id' =\u003e 3, 'title' =\u003e 'Javascript'],\n    ];\n\n    $json-\u003edemo-\u003eupdates($data);\n```\nYou must identify primary key value in the array.\n\n### 6. Delete\n```\n    $json-\u003edemo-\u003edelete(2);                       // Delete one record\n    $json-\u003edemo-\u003edelete([2, 3, 5]);               // Delete some records\n    $json-\u003edemo-\u003edelete('*');                     // Delete *all* records\n```\n\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgarymengcom%2Fjsondb","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgarymengcom%2Fjsondb","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgarymengcom%2Fjsondb/lists"}