codin/dbal

Table Gateway pattern wrapper for Doctrine DBAL

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

This package is auto-updated.

Last update: 2024-04-10 11:53:05 UTC


README

This is not a full orm, this is only a tribute.

Usage

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"