Skip to content

arillo/silverstripe-multidb

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 

Repository files navigation

Arillo\MultiDB

[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' => '[email protected]',
]);

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

$item->exists(); // true

// update record
$item->update([
    'Email' => '[email protected]',
])->write();

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

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

@TODO

  • tests
  • migrations
  • ...

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages