Cycle ORM Schema Builder
Schema Builder configures the Cycle ORM and database schema from entity definitions, produced by annotations (attributes) or by custom generators.
composer require cycle/schema-builderRequires PHP 8.2+.
use Cycle\Database;
use Cycle\Database\Config;
$dbal = new Database\DatabaseManager(new Config\DatabaseConfig([
'default' => 'default',
'databases' => [
'default' => [
'connection' => 'sqlite'
]
],
'connections' => [
'sqlite' => new Config\SQLiteDriverConfig(
connection: new Config\SQLite\MemoryConnectionConfig(),
queryCache: true,
),
]
]));
$registry = new \Cycle\Schema\Registry($dbal);Register an entity, add its columns and link it to a table:
use Cycle\Schema\Definition;
$entity = new Definition\Entity();
$entity
->setRole('user')
->setClass(User::class);
// add fields
$entity->getFields()
->set('id', (new Definition\Field())->setType('primary')->setColumn('id')->setPrimary(true))
->set('name', (new Definition\Field())->setType('string(32)')->setColumn('user_name'));
// register entity
$registry->register($entity);
// associate table
$registry->linkTable($entity, 'default', 'users');Generate the ORM schema with Cycle\Schema\Compiler:
use Cycle\Schema\Compiler;
$schema = (new Compiler())->compile($registry);
$orm = $orm->with(schema: new \Cycle\ORM\Schema($schema));More about the Schema Builder is in the documentation.
The tests run on Testo through the shared cycle/testing harness: tests/Unit needs no database, and tests/Feature runs once per database driver.
composer test:unit # no database
composer test:sqlite # in-memory SQLite, no docker
composer db:up # MySQL, Postgres and SQL Server in docker
composer test # every suite; a driver whose server is down is skipped
composer db:downcomposer test:mysql, test:postgres and test:sqlserver run one driver.