{"id":30141799,"url":"https://github.com/getkirby/database-storage","last_synced_at":"2025-08-11T05:18:48.589Z","repository":{"id":303977317,"uuid":"1017367332","full_name":"getkirby/database-storage","owner":"getkirby","description":"Adds support for pages stored in a database","archived":false,"fork":false,"pushed_at":"2025-07-10T13:55:29.000Z","size":73,"stargazers_count":9,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-07-10T19:56:26.716Z","etag":null,"topics":["database","kirby-cms","kirby-plugin","kirby5"],"latest_commit_sha":null,"homepage":"https://getkirby.com","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/getkirby.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,"zenodo":null},"funding":{"custom":["https://getkirby.com/buy"]}},"created_at":"2025-07-10T12:29:46.000Z","updated_at":"2025-07-10T19:25:24.000Z","dependencies_parsed_at":"2025-07-10T19:56:32.624Z","dependency_job_id":"d0b558be-6f6d-4c16-990b-d4300151fc29","html_url":"https://github.com/getkirby/database-storage","commit_stats":null,"previous_names":["getkirby/database-storage"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/getkirby/database-storage","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/getkirby%2Fdatabase-storage","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/getkirby%2Fdatabase-storage/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/getkirby%2Fdatabase-storage/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/getkirby%2Fdatabase-storage/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/getkirby","download_url":"https://codeload.github.com/getkirby/database-storage/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/getkirby%2Fdatabase-storage/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":269833310,"owners_count":24482423,"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","status":"online","status_checked_at":"2025-08-11T02:00:10.019Z","response_time":75,"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","kirby-cms","kirby-plugin","kirby5"],"created_at":"2025-08-11T05:18:47.892Z","updated_at":"2025-08-11T05:18:48.544Z","avatar_url":"https://github.com/getkirby.png","language":"PHP","funding_links":["https://getkirby.com/buy"],"categories":[],"sub_categories":[],"readme":"# Kirby Database Storage Plugin\n\nAdds support for pages stored in a database. \n\n\u003e [!IMPORTANT]  \n\u003e This plugin is still in an early alpha state. Use with caution.\n\n\u003cimg width=\"1364\" height=\"667\" alt=\"database-storage\" src=\"https://github.com/user-attachments/assets/65068f5a-9f54-4d51-b698-dcdc4c437078\" /\u003e\n\n## Features\n\nThis plugin already provides good support for pages from databases, but has still some limitations. Here is a list of supported page features:\n\n- [x] Content Changes \u0026 Translations\n- [x] Changing the page title\n- [x] Changing the slug\n- [x] Translating the slug\n- [x] Deleting pages\n- [x] Sorting pages\n- [x] Changing the page status\n- [ ] Duplicating pages\n- [ ] Moving pages\n- [ ] Changing templates\n\n### File support \n\nFiles are stored in the content folder. A folder for each page is created as soon as files are uploaded. The UUID is used as folder name. File information is still stored in text files and not yet in the database.\n\n\u003e [!WARNING]  \n\u003e This plugin requires UUIDs to be switched on\n\n## Installation\n\n### Download\n\nDownload and copy this repository to `/site/plugins/database-storage`.\n\n### Composer\n\n```\ncomposer require getkirby/database-storage\n```\n\n### Git submodule\n\n```\ngit submodule add https://github.com/getkirby/database-storage.git site/plugins/database-storage\n```\n\n## How it works?\n\n### Setting up a database\n\nFor this example, we are creating a new SQLite database in `/site/db` and call it `comments.sqlite`. But you can place it everywhere you like and then later change the path in the config. (see below)\n\n### Required fields\n\nOur database models require a couple core fields to work correctly:\n\n| Field name | Type | Config\n| - | - | - |\n| id | INTEGER | primary key, autoincrement, not null, unique\n| title | TEXT |\n| slug | TEXT | not null\n| uuid | TEXT | not null\n| created | TEXT | not null, default: CURRENT_TIMESTAMP\n| modified | TEXT | not null, default: CURRENT_TIMESTAMP\n| version | TEXT | not null\n| language | TEXT | not null\n| parent | TEXT |\n| template | TEXT |\n| num | INTEGER | default: NULL\n| lock | TEXT |\n| draft | INTEGER | not null, default: 1\n\nSQLite has a very limited set of column types. You might want to choose more appropriate types for MySQL or other databases.\n\nOnce all those columns are in place, you can add your own custom columns for custom fields. For our comments example, we will create a `text` and an `email` column.\n\nHere's a full SQL query to create our comments database.\n\n```sql\nCREATE TABLE \"comments\" (\n\t\"id\" INTEGER UNIQUE NOT NULL PRIMARY KEY ASC AUTOINCREMENT,\n\t\"title\" TEXT,\n\t\"slug\" TEXT NOT NULL,\n\t\"uuid\" TEXT NOT NULL,\n\t\"created\" TEXT DEFAULT CURRENT_TIMESTAMP NOT NULL,\n\t\"modified\" TEXT DEFAULT CURRENT_TIMESTAMP NOT NULL,\n\t\"version\" TEXT NOT NULL,\n\t\"language\" TEXT NOT NULL,\n\t\"parent\" TEXT,\n\t\"template\" TEXT,\n\t\"num\" INTEGER DEFAULT NULL,\n\t\"lock\" TEXT,\n\t\"draft\" INTEGER DEFAULT 1 NOT NULL\n\t\"text\" TEXT,\n\t\"email\" TEXT\n);\n```\n\n### Create a table using the Kirby CLI\n\nIf you are using the Kirby CLI, you can create a new table via the `table:create` command:\n\n```bash\nkirby table:create\n```\n\nYou will be asked to specify the database connection, the table name and the list of custom fields.\n\nYou can also provide database connection and table name immediately via arguments:\n\n```bash\nkirby table:create myDatabase myTable\n```\n\n`myDatabase` is referencing the config `key` for the database connection defined in your config (see below)\n\n### Database Connection\n\nWe need to define the connection to our database in the `/site/config/config.php` under the `database` key. The name for the connection can be defined by you, but needs to match later with the `DATABASE_NAME` constant in our page model (see below)\n\n```php\n\u003c?php\n\nuse Kirby\\Database\\Database;\n\nreturn [\n    'database' =\u003e [\n        'comments' =\u003e new Database([\n            'type'     =\u003e 'sqlite',\n            'database' =\u003e dirname(__DIR__) . '/db/comments.sqlite'\n        ])\n    ]\n];\n```\n\n### Parent page\n\nFirst, create a regular Kirby page that serves as the parent for your database pages. For our comments example, we create a new content folder called `/content/comments` with a text file called `comments.txt`. This will connect the page to a new `comments.php` template and – more importantly – a new `CommentsPage` model. This model is the key to load our child pages from the database (see the setup below)\n\n### Models\n\nFor the new comments page, the model will use the `HasDatabaseChildren` trait from our plugin. This trait will replace the `$page-\u003echildren()` method and load children from our database. All we need to do is to define the child model with the `DATABASE_CHILD_MODEL` constant.\n\n**`/site/models/comments.php`**\n```php\n\u003c?php\n\nuse Kirby\\Cms\\Page;\nuse Kirby\\DatabaseStorage\\HasDatabaseChildren;\n\nclass CommentsPage extends Page\n{\n    use HasDatabaseChildren;\n\n    public const DATABASE_CHILD_MODEL = CommentPage::class;\n}\n```\n\n**`/site/models/comment.php`**\n\nEach child of the comments page will now use a new `CommentPage` model and that model needs to extend the `DatabasePage` class from the plugin to make everything work. This class will overwrite all the page action methods to create, update and delete pages in the database and no longer on disk.\n\nThe constants in the model finalize our setup. `DATABASE_NAME` refers to our config setting (`database.comments`), `DATABASE_TABLE` needs to match the table name in our database and the `DATABASE_FIELDS` array defines all custom fields that are stored in the table. The required core fields (see above) are not included here.\n\n```php\n\u003c?php\n\nuse Kirby\\DatabaseStorage\\DatabasePage;\n\nclass CommentPage extends DatabasePage\n{\n    public const DATABASE_NAME = 'comments';\n    public const DATABASE_TABLE = 'comments';\n    public const DATABASE_FIELDS = [\n        'text',\n        'email',\n    ];\n}\n```\n\n## Blueprints\n\nOnce the models are set up correctly, you can define your blueprints and sections exactly like you would before: \n\n**/site/blueprints/pages/comments.yaml**\n```yaml\ntitle: Comments\nsections:\n  comments:\n    type: pages\n    template: comment\n```\n\n**/site/blueprints/pages/comment.yaml**\n```yaml\ntitle: Comment\nfields:\n  text:\n    type: textarea\n  email:\n    type: email\n```\n\n## What’s Kirby?\n\n- **[getkirby.com](https://getkirby.com)** – Get to know the CMS.\n- **[Try it](https://getkirby.com/try)** – Take a test ride with our online demo. Or download one of our kits to get started.\n- **[Documentation](https://getkirby.com/docs/guide)** – Read the official guide, reference and cookbook recipes.\n- **[Issues](https://github.com/getkirby/kirby/issues)** – Report bugs and other problems.\n- **[Feedback](https://feedback.getkirby.com)** – You have an idea for Kirby? Share it.\n- **[Forum](https://forum.getkirby.com)** – Whenever you get stuck, don't hesitate to reach out for questions and support.\n- **[Discord](https://chat.getkirby.com)** – Hang out and meet the community.\n- **[Mastodon](https://mastodon.social/@getkirby)** – Follow us in the Fediverse.\n- **[Bluesky](https://bsky.app/profile/getkirby.com)** – Follow us on Bluesky.\n\n---\n\n## License\n\nMIT\n\n## Credits\n\n- [Kirby Team](https://getkirby.com)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgetkirby%2Fdatabase-storage","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgetkirby%2Fdatabase-storage","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgetkirby%2Fdatabase-storage/lists"}