readdle / fqorm
Simple ORM
Installs: 36
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 5
Forks: 0
Open Issues: 0
pkg:composer/readdle/fqorm
Requires
- php: >=7.4
 - readdle/fqdb: ^4.1
 
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.3
 - phpstan/phpstan: ^1.2
 - phpunit/phpunit: ^9
 
README
Very simple ORM layer, based on the Data Mapper pattern.
Some key design principles:
- There are two types of classes: Mapper and Entity
 - Entities contain data; they have properties, may have formatting methods, validation, etc.
 - Mapper can read and write Entities from the database
 - There are two abstract classes AbstractMapper and AbstractMapperId that can be used to create you own Mappers quickly.
 - You can create any methods for Mapper, but typically we use 
save,delete,findByID,findByWhere, etc. 
Not a rules
These are not rules, but things are very simple when it happens this way:
- Each Entity has its own Mapper
 - Each Mapper maps Entity to one specific database table
 - Entity has a structure similar to specific database table
 
If you do things differently, existing abstract classes won't help you.
How to create Entity and Mapper
See ExampleIdEntity.php and ExampleIdMapper.php.
- Entities just have some properties
 - Mappers extend 
AbstractMapperorAbstractMapperIDand override methodsmapperTableName,mapperEntityClass - In another override method 
createFieldMappingyou have to describe mapping for all fields - For 
AbstractMappersubclasses you have to describe unique (key) fields increateFieldMappingUnique. ClassAbstractMapperIDalready does this forid. - Implement a save, delete, find... methods annotated with your specific Entity types. You may use existing untyped* methods of parent classes.