[Experimental] Simple DataObject proxy helping to persist records in multiple databases.
SilverStripe CMS ^4.0
composer require arillo/silverstripe-multidb
<?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();
- tests
- migrations
- ...