Skip to content

Commit 0a03b5d

Browse files
committed
Merge remote-tracking branch 'origin/master'
2 parents 8c0d50b + 18861aa commit 0a03b5d

File tree

1 file changed

+38
-1
lines changed

1 file changed

+38
-1
lines changed

README.md

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# 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.
33

44
This is dibi/nette bridge for https://github.com/dodo-it/entity-generator/
55

@@ -30,8 +30,45 @@ entityGenerator:
3030
extends: App\Model\Entities\BaseEntity
3131
generateGetters: false
3232
generateSetters: false
33+
extends: DodoIt\EntityGenerator\Entity
3334
propertyVisibility: 'public'
3435
```
3536
You can see list of all options and their default values in:
3637
https://github.com/dodo-it/entity-generator/blob/master/src/Generator/Config.php
3738
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

Comments
 (0)