PHPackages                             getkirby/database-storage - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. getkirby/database-storage

ActiveKirby-plugin[Database &amp; ORM](/categories/database)

getkirby/database-storage
=========================

Kirby Database Storage

1.0.0-alpha.1(10mo ago)28121[3 issues](https://github.com/getkirby/database-storage/issues)[1 PRs](https://github.com/getkirby/database-storage/pulls)MITPHPPHP &gt;=8.1.0

Since Jul 10Pushed 10mo ago1 watchersCompare

[ Source](https://github.com/getkirby/database-storage)[ Packagist](https://packagist.org/packages/getkirby/database-storage)[ Docs](https://getkirby.com)[ Fund](https://getkirby.com/buy)[ RSS](/packages/getkirby-database-storage/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (7)Versions (2)Used By (0)

Kirby Database Storage Plugin
=============================

[](#kirby-database-storage-plugin)

Adds support for pages stored in a database.

Important

This plugin is still in an early alpha state. Use with caution.

[![database-storage](https://private-user-images.githubusercontent.com/24532/464760712-65068f5a-9f54-4d51-b698-dcdc4c437078.png?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3NzU0OTUzNjAsIm5iZiI6MTc3NTQ5NTA2MCwicGF0aCI6Ii8yNDUzMi80NjQ3NjA3MTItNjUwNjhmNWEtOWY1NC00ZDUxLWI2OTgtZGNkYzRjNDM3MDc4LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNjA0MDYlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjYwNDA2VDE3MDQyMFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWMyZWQ5YWYzOTRlNDZlM2VlYjU0OTFmYWY1ZThkOTk2ODQwNzYxNDg1NzY5ODc5NDIxNTY5MmUwNmE2OTliYzMmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.lZmzlkELmLS7kRjjO0NB6YT2FlK3s1T0HPjiyUUbAiU)](https://private-user-images.githubusercontent.com/24532/464760712-65068f5a-9f54-4d51-b698-dcdc4c437078.png?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3NzU0OTUzNjAsIm5iZiI6MTc3NTQ5NTA2MCwicGF0aCI6Ii8yNDUzMi80NjQ3NjA3MTItNjUwNjhmNWEtOWY1NC00ZDUxLWI2OTgtZGNkYzRjNDM3MDc4LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNjA0MDYlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjYwNDA2VDE3MDQyMFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWMyZWQ5YWYzOTRlNDZlM2VlYjU0OTFmYWY1ZThkOTk2ODQwNzYxNDg1NzY5ODc5NDIxNTY5MmUwNmE2OTliYzMmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.lZmzlkELmLS7kRjjO0NB6YT2FlK3s1T0HPjiyUUbAiU)Features
--------

[](#features)

This plugin already provides good support for pages from databases, but has still some limitations. Here is a list of supported page features:

- Content Changes &amp; Translations
- Changing the page title
- Changing the slug
- Translating the slug
- Deleting pages
- Sorting pages
- Changing the page status
- Duplicating pages
- Moving pages
- Changing templates

### File support

[](#file-support)

Files 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.

Warning

This plugin requires UUIDs to be switched on

Installation
------------

[](#installation)

### Download

[](#download)

Download and copy this repository to `/site/plugins/database-storage`.

### Composer

[](#composer)

```
composer require getkirby/database-storage

```

### Git submodule

[](#git-submodule)

```
git submodule add https://github.com/getkirby/database-storage.git site/plugins/database-storage

```

How it works?
-------------

[](#how-it-works)

### Setting up a database

[](#setting-up-a-database)

For 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)

### Required fields

[](#required-fields)

Our database models require a couple core fields to work correctly:

Field nameTypeConfigidINTEGERprimary key, autoincrement, not null, uniquetitleTEXTslugTEXTnot nulluuidTEXTnot nullcreatedTEXTnot null, default: CURRENT\_TIMESTAMPmodifiedTEXTnot null, default: CURRENT\_TIMESTAMPversionTEXTnot nulllanguageTEXTnot nullparentTEXTtemplateTEXTnumINTEGERdefault: NULLlockTEXTdraftINTEGERnot null, default: 1SQLite has a very limited set of column types. You might want to choose more appropriate types for MySQL or other databases.

Once 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.

Here's a full SQL query to create our comments database.

```
CREATE TABLE "comments" (
	"id" INTEGER UNIQUE NOT NULL PRIMARY KEY ASC AUTOINCREMENT,
	"title" TEXT,
	"slug" TEXT NOT NULL,
	"uuid" TEXT NOT NULL,
	"created" TEXT DEFAULT CURRENT_TIMESTAMP NOT NULL,
	"modified" TEXT DEFAULT CURRENT_TIMESTAMP NOT NULL,
	"version" TEXT NOT NULL,
	"language" TEXT NOT NULL,
	"parent" TEXT,
	"template" TEXT,
	"num" INTEGER DEFAULT NULL,
	"lock" TEXT,
	"draft" INTEGER DEFAULT 1 NOT NULL
	"text" TEXT,
	"email" TEXT
);
```

### Create a table using the Kirby CLI

[](#create-a-table-using-the-kirby-cli)

If you are using the Kirby CLI, you can create a new table via the `table:create` command:

```
kirby table:create
```

You will be asked to specify the database connection, the table name and the list of custom fields.

You can also provide database connection and table name immediately via arguments:

```
kirby table:create myDatabase myTable
```

`myDatabase` is referencing the config `key` for the database connection defined in your config (see below)

### Database Connection

[](#database-connection)

We 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)

```
