sixacross/vinyl

A relational data mapper library

dev-main 2022-01-25 03:10 UTC

This package is not auto-updated.

Last update: 2024-04-16 13:23:50 UTC


README

A relational data mapper library

Usage

A brief demo of how to use RecordStores (the repository/mapper) and Records (the entity/model) to CRUD data.

use PDO;
use Doctrine\DBAL\DriverManager;
use Doctrine\DBAL\Configuration;
use SixAcross\Vinyl\V1 as Vinyl;

$pdo = new PDO( mysql:dbname=vinyl', 'vinyl', 'some_password' );
$connection = DriverManager::getConnection( [ 'pdo' => $pdo, ], new Configuration );

// see Vinyl\V1\RecordStore for the full interface
$user_store = new Vinyl\RecordStore\SQL\PDO\Doctrine( 
    'users', 
    $connection->createQueryBuilder(),
    new Vinyl\RecordProducer\PDO\Statement( new Vinyl\Record\Generic )
  );


// see Vinyl\V1\Record for the full interface
$user = $user_store->insertRecord([ 'first_name' => 'June', 'last_name' => 'Roderick', ]);

$user = $user_store->getRecord( 99 );

$user['last_name'] = 'Rodriguez';

$user_store->updateRecord( $user );

$user_store->deleteRecord( $user );