codin/dbal

Doctrine DBAL 的 Table Gateway 模式包装器

dev-master 2021-07-10 06:03 UTC

This package is auto-updated.

Last update: 2024-09-10 12:44:03 UTC


README

这并不是一个完整的 ORM,这只是一个致敬。

使用方法

class Product
{
    protected string $uuid;

    protected string $desc;

    public function getUuid(): string
    {
        return $this->uuid;
    }

    public function getDesc(): string
    {
        return $this->desc;
    }
}

class Products extends Codin\DBAL\TableGateway
{
    protected string $table = 'products';

    protected string $primary = 'uuid';

    protected string $model = Product::class;
}

$conn = new Doctrine\DBAL\Connection(['pdo' => new PDO('sqlite:products.db')]);
$conn->exec('create table if not exists products (uuid string, desc string)');

$products = new Products($conn);
$products->insert(['desc' => 'banana', 'uuid' => 'BAN01']);
$banana = $products->fetch();
echo $product->getDesc(); // "banana"