六横线/乙烯基

关系型数据映射库

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

This package is not auto-updated.

Last update: 2024-10-01 15:45:28 UTC


README

关系型数据映射库

用法

一个简短演示,展示如何使用RecordStores(仓库/映射器)和Records(实体/模型)进行CRUD数据操作。

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 );