{"id":16124344,"url":"https://github.com/jongacnik/kirby2-datastore","last_synced_at":"2025-06-22T20:41:19.306Z","repository":{"id":68335740,"uuid":"100896654","full_name":"jongacnik/kirby2-datastore","owner":"jongacnik","description":"Kirby flat-file json datastore for large-ish quantities of data","archived":false,"fork":false,"pushed_at":"2017-09-13T23:16:27.000Z","size":490,"stargazers_count":2,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-12T18:18:51.860Z","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/jongacnik.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-08-21T00:20:08.000Z","updated_at":"2023-01-17T01:13:10.000Z","dependencies_parsed_at":"2023-04-05T01:44:27.926Z","dependency_job_id":null,"html_url":"https://github.com/jongacnik/kirby2-datastore","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/jongacnik%2Fkirby2-datastore","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jongacnik%2Fkirby2-datastore/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jongacnik%2Fkirby2-datastore/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jongacnik%2Fkirby2-datastore/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jongacnik","download_url":"https://codeload.github.com/jongacnik/kirby2-datastore/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247479523,"owners_count":20945476,"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":"2024-10-09T21:20:43.144Z","updated_at":"2025-04-06T12:22:47.737Z","avatar_url":"https://github.com/jongacnik.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Kirby Datastore\n\nProvides Kirby with a flat-file json datastore for housing large-ish quantities of data, and a panel field for managing this data.\n\n## Instance\n\n```php\n// Get datastore instance\n$database = site()-\u003edatastore();\n\n// Get/Create a collection \n$people = $database-\u003ecollection('people');\n\n// Get entries as array\n$people-\u003efind();\n```\n\nThe datastore is implemented with [Jisly](https://github.com/r0mdau/jisly), so refer to those docs for all methods. Sorry for the French but the code examples are good!\n\n## Field\n\nThe `datastore` field is an extension of the structure field. Instead of the entries being saved into a page text file as yaml, the entries are saved to the datastore.\n\n```yaml\npeople:\n  label: People\n  type: datastore\n  fields:\n    name:\n      label: Name\n      type: text\n    age:\n      label: Age\n      type: number\n```\n\nTo access entries from the template:\n\n```php\nsite()-\u003edatastore('people')-\u003efind();\n```\n\n### Field Options\n\n```yaml\npeople:\n  label: People\n  type: datastore\n  collection: persons\n  fields:\n    name:\n      label: Name\n      type: text\n    email:\n      label: Email\n      type: email\n    age:\n      label: Age\n      type: number\n    glasses:\n      label: Glasses\n      type: toggle\n  columns:\n    name: Name\n    email: \n      label: Email\n      class: emailcolumnclass\n    details:\n      label: Details\n      width: 20%\n    glasses:\n      label: Glasses\n      sort: false\n  order: desc\n  rows: 25\n\n```\n\n## Options\n\nDefaults shown\n\n```php\nc::set('datastore.location', kirby()-\u003eroots()-\u003econtent());\nc::set('datastore.dbname', 'datastore');\nc::set('datastore.method', 'datastore');\n```\n\n## Usage\n\n```yaml\nentries:\n  label: Entries\n  type: datastore\n```\n\n## Filter Data\nA custom filter can be applied to the data before it is put out as a json response. This is perfect if you need to modify some of the data for presentation, change columns, etc.\n\nCreate a simple plugin `site/plugins/mydatafilters/mydatafilters.php`:\n```php\n\u003c?php\n\nclass MyDataFilters {\n  static function myfilterfunc($data) {\n    // filter data here\n    return $data;\n  }\n}\n```\n\nUpdate field definition:\n```yaml\npeople:\n  label: People\n  type: datastore\n  collection: persons\n  filter: MyDataFilters::myfilterfunc\n  fields:\n    name:\n      label: Name\n      type: text\n    age:\n      label: Age\n      type: number\n```\n\n## Why?\n\nSometimes I need to store large-ish quantities of data, think along the lines of 10,000+ entries with 10+ fields. With Kirby we have 2 built-in options:\n\n- 10,000 pages\n- 10,000 structure (yaml) entries\n\n10,000 pages is a mess and quite slow, especially if you need to iterate over and filter that data. The advantage to the Kirby flat-file system is in a tree-based structure; 10,000 subfolders isn’t making the best use of that.\n\n10,000 structure entries initially feels more sane, but will be a nightmare to manage in the panel, and Kirby’s `yaml` or `toStructure` methods become quite slow on this many entries, so iterating and filtering is also an issue here.\n\nI needed a different way to store data, but wanted the solution to remain flat-file to not break with the Kirby ethos, and wanted the data modelable and editable via the panel.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjongacnik%2Fkirby2-datastore","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjongacnik%2Fkirby2-datastore","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjongacnik%2Fkirby2-datastore/lists"}