Entity generator from database for dibi

1.1.1 2020-12-08 11:17 UTC

This package is auto-updated.

Last update: 2021-08-29 10:03:15 UTC


Highly configurable typed entity generator from database. It can generate entities for whole database, table/view and from queries.

This is dibi/nette bridge for

Latest Stable Version Total Downloads License


$ composer require dodo-it/dibi-entity-generator


    entityGenerator: DodoIt\DibiEntityGenerator\DI\DibiEntityGeneratorExtension



    path: %appDir%/Model/Entity
    namespace: App\Model\Entity
    extends: App\Model\Entities\BaseEntity
    generateGetters: false
    generateSetters: false
    extends: DodoIt\EntityGenerator\Entity
    propertyVisibility: 'public'

You can see list of all options and their default values in:


Abstract entity class

First create your BaseEntity class which all entities will extends and set option extends to that class in your configuration. As a starting point you can just Use Dibi\Row and set to only generate phpdoc comments that way nothing will change but you will have full autocomplete in your queries. Better scenario would be to generate getters and setters which then can have return typehints...

Example code in repository

public function getById(int $id): ArticleEntity
		return $this->db->select('*')->from('articles')->where('id = %i', $id)

Generate all

To generate all entities run from database tables and views run

console entity:generate 

Generate one table/view only

console entity:generate table_name

Generate from query

Write your query in .sql file after that run command:

 console entity:generate --query-file=path/to/QueryFile.sql EntityName

Generate from directory where query sql files are

Write your queries in one folder in .sql files and (re) generate entities for all queries with:

 console entity:generate --query-dir=/path/to/dir