arillo / silverstripe-multidb
Simple DataObject proxy helping to persist records in multiple databases
Installs: 80
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 5
Forks: 0
Open Issues: 0
Type:silverstripe-vendormodule
Requires
- catfan/medoo: ^1.5
- silverstripe/framework: ^4
This package is auto-updated.
Last update: 2024-12-09 03:12:42 UTC
README
[Experimental] Simple DataObject proxy helping to persist records in multiple databases.
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
- ...