attreid / orm-structure
Nextras/ORM Structure extension
2.3.2
2023-03-15 08:33 UTC
Requires
- php: >= 8.1
- ext-json: *
- nette/di: ~3.0
- nextras/orm: ~4.0
Requires (Dev)
- nette/tester: ~2.4
- tracy/tracy: ~2.8
- dev-master / 2.x-dev
- 2.3.2
- 2.3.1
- 2.3.0
- 2.2.3
- 2.2.2
- 2.2.1
- 2.2.0
- 2.1.0
- 2.0.4
- 2.0.3
- 2.0.2
- 2.0.1
- 2.0.0
- 1.11.0
- 1.10.1
- 1.10.0
- 1.9.1
- 1.9.0
- 1.8.4
- 1.8.3
- 1.8.2
- 1.8.1
- 1.8.0
- 1.7.6
- 1.7.5
- 1.7.4
- 1.7.3
- 1.7.2
- 1.7.1
- 1.7.0
- 1.6.13
- 1.6.12
- 1.6.11
- 1.6.10
- 1.6.9
- 1.6.8
- 1.6.7
- 1.6.6
- 1.6.5
- 1.6.4
- 1.6.3
- 1.6.2
- 1.6.1
- 1.6.0
- 1.5.12
- 1.5.11
- 1.5.10
- 1.5.9
- 1.5.8
- 1.5.7
- 1.5.6
- 1.5.5
- 1.5.4
- 1.5.3
- 1.5.2
- 1.5.1
- 1.5.0
- 1.4.0
- 1.3.6
- 1.3.5
- 1.3.4
- 1.3.3
- 1.3.2
- 1.3.1
- 1.3.0
- 1.2.7
- 1.2.6
- 1.2.5
- 1.2.4
- 1.2.3
- 1.2.2
- 1.2.1
- 1.2.0
- 1.1.1
- 1.1.0
- 1.0.13
- 1.0.12
- 1.0.11
- 1.0.10
- 1.0.9
- 1.0.8
- 1.0.7
- 1.0.6
- 1.0.5
- 1.0.4.1
- 1.0.4
- 1.0.3
- 1.0.2
- 1.0.1
- 1.0.0
This package is auto-updated.
Last update: 2025-01-15 12:15:35 UTC
README
Settings config.neon
extensions: structure: Attreid\OrmStructure\DI\StructureExtension structure: autoManageDb: true
Table Mapper
class ExampleMapper extends \Attreid\OrmStructure\TableMapper { public function createTable(\Attreid\Orm\Structure\Table $table) { $table->setDefaultDataFile(__DIR__.'/import.sql'); $table->addPrimaryKey('id') ->int() ->setAutoIncrement(); $table->addForeignKey('some_id', SomeMapper::class); $table->addForeignKey('parent_id', $table) ->setDefault(NULL); $table->addColumn('pa') ->varChar(20); $table->addColumn('allowed') ->boolean() ->setDefault(1) ->setKey(); $table->addUnique('some_id', 'parent_id'); $table->addFulltext('pa'); $relationTable = $table->createRelationTable(OtherMapper::class); $relationTable->addForeignKey('example_id', $table); $relationTable->addForeignKey('other_id', OtherMapper::class); $relationTable->setPrimaryKey('example_id', 'other_id'); // migration if (!$relationTable->exists) { $table->migration[] = function (Row $row, Connection $connection) use ($relationTable) { if (isset($row->oldColumnId)) { $connection->query('INSERT INTO %table %values', $relationTable->name, [ 'exampleId' => $row->id, 'otherId' => $row->oldColumnId ]); } }; } $table->addOnCreate([ [ 'id' => 1, 'some_id' => 1, 'parent_id' => 1, 'pa' => 'test', // ... ] ]); } }
View Mapper
class ExampleMapper extends \Attreid\OrmStructure\ViewMapper { public function createDefinition(QueryBuilder $builder): void { $builder ->addSelect('ROW_NUMBER() OVER (ORDER BY some_row) id') ->addSelect('another_row') ->from('some_table', 't'); } protected function getPrimaryKey(): array { return ['id']; } protected function getMapping(): array { return []; // OR return [ 'another' => 'currency_row' ]; } }