|
1 | 1 | # Dibi Entity generator |
2 | | -Typed entity generator from database. It can generate entities for whole database, table/view and from query. |
| 2 | +Highly configurable typed entity generator from database. It can generate entities for whole database, table/view and from query. |
3 | 3 |
|
4 | 4 | This is dibi/nette bridge for https://github.com/dodo-it/entity-generator/ |
5 | 5 |
|
@@ -30,8 +30,45 @@ entityGenerator: |
30 | 30 | extends: App\Model\Entities\BaseEntity |
31 | 31 | generateGetters: false |
32 | 32 | generateSetters: false |
| 33 | + extends: DodoIt\EntityGenerator\Entity |
33 | 34 | propertyVisibility: 'public' |
34 | 35 | ``` |
35 | 36 | You can see list of all options and their default values in: |
36 | 37 | https://github.com/dodo-it/entity-generator/blob/master/src/Generator/Config.php |
37 | 38 | |
| 39 | +## Usage |
| 40 | +
|
| 41 | +### Abstract entity class |
| 42 | + First create your BaseEntity class which all entities will extends and set option extends to that class in your configuration. |
| 43 | + 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. |
| 44 | +Better scenario would be to generate getters and setters which then can have return typehints... |
| 45 | +
|
| 46 | +### Example code in repository |
| 47 | +```php |
| 48 | +public function getById(int $id): ArticleEntity |
| 49 | +{ |
| 50 | + return $this->db->select('*')->from('articles')->where('id = %i', $id) |
| 51 | + ->execute() |
| 52 | + ->setRowClass(ArticleEntity::class) |
| 53 | + ->fetch(); |
| 54 | +} |
| 55 | +``` |
| 56 | + |
| 57 | +### Generate all |
| 58 | +To generate all entities run from database tables and views run |
| 59 | +```ssh |
| 60 | +console entity:generate |
| 61 | +``` |
| 62 | +### Generate one table/view only |
| 63 | + |
| 64 | +```ssh |
| 65 | +console entity:generate table_name |
| 66 | +``` |
| 67 | + |
| 68 | +### Generate from query |
| 69 | +Write your query in .sql file and put it into app/Models/Queries/ |
| 70 | +after that run command: |
| 71 | + |
| 72 | +```ssh |
| 73 | + console entity:generate --query-file=app/Models/Queries/Query.sql EntityName |
| 74 | +``` |
0 commit comments