silassare / gobl
Gobl allows you to use a Database Abstraction Layer (DBAL) and Object-Relational Mapping (ORM) to query your database with PHP.
1.5.0
2021-05-15 10:58 UTC
Requires
- php: >=5.6.0
- ext-bcmath: *
- ext-json: *
- ext-pdo: *
- silassare/otpl: =1.1.9
Requires (Dev)
README
A PHP 8.1+ Database Abstraction Layer (DBAL) and ORM with code generation for MySQL/MariaDB, PostgreSQL, and SQLite.
Features
- Schema-first: define tables, columns, constraints, and relations in PHP arrays or a fluent builder
- Typed query builder:
QBSelect,QBInsert,QBUpdate,QBDeletewith safe PDO value binding - Code generation: strongly-typed PHP entity, controller, query, and CRUD classes per table
- Event-driven CRUD: before/after hooks for every write operation via
*Crudclasses - Multi-driver: one schema, three databases - MySQL/MariaDB, PostgreSQL, SQLite
- Migration engine:
Diffbetween schema versions +MigrationRunner
Requirements
- PHP >= 8.1
- PDO extension with at least one of:
pdo_mysql,pdo_pgsql,pdo_sqlite
Installation
composer require silassare/gobl
Documentation
Full documentation on GitHub:
Quick example
use Gobl\DBAL\Drivers\MySQL\MySQL; use Gobl\DBAL\DbConfig; $db = MySQL::newInstanceOf(new DbConfig([ 'db_host' => '127.0.0.1', 'db_name' => 'myapp', 'db_user' => 'root', 'db_pass' => 'secret', ])); $db->ns('App\Db')->schema([ 'users' => [ 'singular_name' => 'user', 'plural_name' => 'users', 'column_prefix' => 'user', 'constraints' => [ ['type' => 'primary_key', 'columns' => ['id']], ], 'columns' => [ 'id' => ['type' => 'bigint', 'auto_increment' => true, 'unsigned' => true], 'name' => ['type' => 'string', 'max' => 60], ], ], ])->enableORM('/path/to/output');
License
MIT