beebmx/kirby-db

Enable Kirby 3 database support for Illuminate\Database

Installs: 757

Dependents: 0

Suggesters: 0

Security: 0

Stars: 11

Watchers: 2

Forks: 5

Open Issues: 0

Type:kirby-plugin

1.0.4 2020-06-08 15:32 UTC

This package is auto-updated.

Last update: 2022-01-08 18:48:21 UTC


README

Kirby DB use Laravel illuminate/database package and enable their features for Kirby.

This package enable Laravel Query Builder, Laravel Eloquent ORM and Laravel Schema for your own Kirby applications.

Installation

Installation with composer

composer require beebmx/kirby-db

Usage

First you need to set your database in your config/config.php file:

<?php
return [
    'beebmx.kirby-db.drivers' => [
        'sqlite' => [
            'driver' => 'sqlite',
            'database' => 'storage/database/database.sqlite',
            'prefix' => ''
        ]
    ],
];

Usage Query Builder

To use Query Builder:

use Beebmx\KirbyDB\DB;

DB::table('users')->get();

All the documentation about Query Builder is in the official documentation.

Usage Eloquent ORM

To use Eloquent ORM, first you need to create a Model:

use Beebmx\KirbyDB\Model;

class User extends Model {

}

Then you can use your new model with:

\User::all();

All the documentation about Eloquent ORM is in the official documentation.

Options

The default values of the package are:

Option Default Values Description
beebmx.kirby-db.default sqlite mysql / sqlite / pgsql / sqlsrv Default driver
beebmx.kirby-db.drivers [] (array) Array with all the drivers available
beebmx.kirby-db.eloquent false true / false Enable Eloquent ORM

Driver Examples

This is an example of the drivers available:

return [
    'beebmx.kirby-db.drivers' => [
        'sqlite' => [
            'driver' => 'sqlite',
            'database' => 'storage/database/database.sqlite',
            'prefix' => '',
        ],
        'mysql' => [
            'driver' => 'mysql',
            'host' => '127.0.0.1',
            'port' => '3306',
            'database' => 'database',
            'username' => 'user',
            'password' => '',
            'unix_socket' => '',
            'charset' => 'utf8mb4',
            'collation' => 'utf8mb4_unicode_ci',
            'prefix' => '',
            'strict' => true,
            'engine' => null,
        ],
        'pgsql' => [
            'driver' => 'pgsql',
            'host' => '127.0.0.1',
            'port' => '5432',
            'database' => 'database',
            'username' => 'user',
            'password' => '',
            'charset' => 'utf8',
            'prefix' => '',
            'schema' => 'public',
            'sslmode' => 'prefer',
        ],
        'sqlsrv' => [
            'driver' => 'sqlsrv',
            'host' => 'localhost',
            'port' => '1433',
            'database' => 'database',
            'username' => 'user',
            'password' => '',
            'charset' => 'utf8',
            'prefix' => '',
        ],
    ],
];

Usage note

You can use Kirby Env to hide your credentials from your code.