arillo/silverstripe-multidb

Simple DataObject proxy helping to persist records in multiple databases

Installs: 9

Dependents: 0

Suggesters: 0

Stars: 0

Watchers: 3

Forks: 0

Open Issues: 0

Type:silverstripe-vendormodule

dev-master 2018-09-13 16:25 UTC

README

[Experimental] Simple DataObject proxy helping to persist records in multiple databases.

Latest Stable Version   Total Downloads

Requirements

SilverStripe CMS ^4.0

Installation

composer require arillo/silverstripe-multidb

Usage

<?php
use SilverStripe\ORM\DataObject;

class MyDataObject extends DataObject
{
    private static
        $table_name = 'MyDataObject',

        $db = [
            'Email' => 'Varchar(255)',
            'FirstName' => 'Varchar(255)',
            'Surname' => 'Varchar(255)',
        ],

        $summary_fields = [
            'Email' => 'Email',
            'FirstName' => 'FirstName',
            'Surname' => 'Surname',
        ]
    ;
}

use Arillo\MultiDB\DataObjectProxy;

class MyDataObjectProxy extends DataObjectProxy
{
    private static
        $dataobject_class = MyDataObject::class
    ;

    public static function db_config()
    {
        // Medoo configurations (@see https://medoo.in/api/new)
        return [
            'database_type' => 'mysql',
            'database_name' => <db_name>,
            'server' => <server>,
            'username' => <username>,
            'password' => <pw>,
        ];
    }
}

// get all
$records = MyDataObjectProxy::get();

// create
$item = MyDataObjectProxy::create([
    'Email' => 'some@email.com',
]);

// save it
$item->write();

$item->exists(); // true

// update record
$item->update([
    'Email' => 'updated@email.com',
])->write();

\SilverStripe\Dev\Debug::dump($item);

// delete record
$item->delete();

@TODO

  • tests
  • migrations
  • ...