{"id":16410745,"url":"https://github.com/justim/dok","last_synced_at":"2026-05-14T20:07:18.911Z","repository":{"id":146131183,"uuid":"69465835","full_name":"justim/dok","owner":"justim","description":"Databases as arrays (very experimental)","archived":false,"fork":false,"pushed_at":"2017-01-28T13:01:48.000Z","size":29,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-10T06:11:23.073Z","etag":null,"topics":["database","php"],"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/justim.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":"2016-09-28T13:27:03.000Z","updated_at":"2020-07-16T11:17:47.000Z","dependencies_parsed_at":null,"dependency_job_id":"6ef74c81-f85c-49dd-abe6-76e7644d4f7d","html_url":"https://github.com/justim/dok","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/justim/dok","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/justim%2Fdok","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/justim%2Fdok/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/justim%2Fdok/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/justim%2Fdok/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/justim","download_url":"https://codeload.github.com/justim/dok/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/justim%2Fdok/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33041269,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-13T13:14:54.681Z","status":"online","status_checked_at":"2026-05-14T02:00:06.663Z","response_time":57,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["database","php"],"created_at":"2024-10-11T06:43:46.282Z","updated_at":"2026-05-14T20:07:18.886Z","avatar_url":"https://github.com/justim.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Dok [![Build Status](https://secure.travis-ci.org/justim/dok.png)](http://travis-ci.org/justim/dok)\n\u003e Databases as arrays\n\n_Note: not really ready for anything production-like_\n\n```php\n$db = \\Dok\\Database::create('sqlite::memory:');\n$db['projects'][] = [\n    'name' =\u003e 'Dok',\n];\necho $db['projects'][1]['name']; // Dok\n```\n\n## Features\n\n### Basic operations\n\nAll basic database operations can be executed with normal array operations.\n\n- Select:\n\n  ```php\n  $db['projects'][1];\n  // SELECT * FROM projects WHERE id = 1\n  ```\n\n- Select multiple:\n\n  ```php\n  foreach ($db['projects'] as $project) { /* ... */ }\n  // SELECT * FROM projects\n  ```\n\n- Insert:\n\n  ```php\n  $db['projects'][] = [ 'name' =\u003e 'Tim' ];\n  // INSERT INTO projects (name) VALUES ('Tim')\n  ```\n\n- Delete:\n\n  ```php\n  unset($db['projects'][1]);\n  // DELETE FROM projects WHERE id = 1\n  ```\n\n- Update:\n\n  ```php\n  $db['projects'][1]['name'] = 'Dok';\n  // UDPATE projects SET name = 'Dok' WHERE id = 1\n  ```\n\n### Linked tables\n\n```php\n// this assumes that the projects table has a `user_id` column,\n// and that a `users` table exists with a `id` column\n$nameOfProjectOwner = $db['projects'][1]['user']['name'];\n\n// using the same assumption, we can also go the other way\n$projectsOfUser = $db['users'][1]['projects'];\n\n// and again using this assumption, inserting is also possible\n$db['users'][1]['projects'][] = [ 'name' =\u003e 'Vice' ];\n// INSERT INTO projects (name, user_id) VALUES ('Vice', 1)\n```\n\nLinked tables behave the same a regular table would, so you can also update/delete those records.\n\n### Joins\n\nSome simple joins can be made. Currently uses a bit of a weird syntax...\n\n```php\n$projectsWithUserName = $db['projects:user.name'];\n// [\n//     'name' =\u003e 'Dok',\n//     'user.name' =\u003e 'Tim',\n// ]\n// SELECT projects.*, users.name AS `user.name`\n// FROM projects LEFT JOIN users ON projects.user_id = users.id\n```\n\nSee the tests for more example on how to use Dok.\n\n## How\n\nSo how does this all work? Basically we execute a query every time a array index is\naccessed and return a new `ArrayAccess` instance representing the thing you asked for.\n\nA Dok database instance represents a database, all the indexes refer to tables, which can only\nbe tables that actually exist (`$db['users']`). You get back a table instance, on which\nyou can fetch records with their `id` (`$db['users'][1]`). After that you can lookup\nfield for this records (`$db['users'][1]['name']`).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjustim%2Fdok","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjustim%2Fdok","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjustim%2Fdok/lists"}