beebmx/kirby-db

Enable Kirby 3 & 4 database support for Illuminate\Database

Installs: 1 885

Dependents: 0

Suggesters: 0

Security: 0

Stars: 16

Watchers: 3

Forks: 4

Open Issues: 0

Type:kirby-plugin

3.1.0 2024-08-02 17:10 UTC

This package is auto-updated.

Last update: 2024-12-02 17:56:20 UTC


README

Latest Stable Version GitHub Workflow Status Total Downloads License

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:

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.