thewunder / corma
Convention-based Alternative ORM
Installs: 10 810
Dependents: 0
Suggesters: 0
Security: 0
Stars: 31
Watchers: 4
Forks: 4
Open Issues: 5
Requires
- php: >=8.1
- ext-json: *
- ext-pdo: *
- doctrine/dbal: ^3.0
- doctrine/inflector: ^1.3||^2.0
- psr/event-dispatcher: ^1.0
- psr/simple-cache: ^1.0||^2.0||^3.0
Requires (Dev)
- php-coveralls/php-coveralls: ~2.0
- phpunit/phpunit: ^10.0
- rector/rector: ^1.0
- symfony/event-dispatcher: ^6.0
- vlucas/phpdotenv: ~2.0
Suggests
- dev-master
- 4.1.0
- 4.0.3
- 4.0.2
- 4.0.1
- 4.0
- 3.x-dev
- 3.6.5
- 3.6.4
- 3.6.3
- 3.6.2
- 3.6.1
- 3.6.0
- 3.5.3
- 3.5.2
- 3.5.1
- 3.5.0
- 3.4.0
- 3.3.4
- 3.3.3
- 3.3.2
- 3.3.1
- 3.3.0
- 3.2.5
- 3.2.4
- 3.2.3
- 3.2.2
- 3.2.1
- 3.2.0
- 3.1.1
- 3.1.0
- 3.0.2
- 3.0.1
- 3.0
- 3.0-beta3
- 3.0-beta2
- 3.0-beta1
- 2.x-dev
- 2.1.6
- 2.1.5
- 2.1.4
- 2.1.3
- 2.1.2
- 2.1.1
- 2.1
- 2.0.2
- 2.0.1
- 2.0
- 2.0-beta2
- 2.0-beta1
- 1.0.x-dev
- 1.0.7
- 1.0.6
- 1.0.5
- 1.0.4
- 1.0.3
- 1.0.2
- 1.0.1
- 1.0.0
- 1.0.0-beta1
- 0.9.0
- 0.8.0
- 0.7.8
- 0.7.7
- 0.7.6
- 0.7.5
- 0.7.4
- 0.7.3
- 0.7.2
- 0.7.1
- 0.7.0
- 0.6.0
- 0.5.1
- 0.5.0
- 0.4.1
- 0.4.0
- 0.3.0
- 0.2.3
- 0.2.2
- 0.2.1
- 0.2.0
- 0.1.1
- 0.1
- dev-relationship_joins
- dev-relationship_refactor
This package is auto-updated.
Last update: 2024-04-03 21:20:21 UTC
README
Corma is a high-performance, convention-based ORM based on Doctrine DBAL.
Corma is great because:
- No complex and difficult to verify annotations or configuration files
- Promotes consistent code organization
- Loads and saves one-to-one, one-to-many, and many-to-many relationships with a method call
- Can save multiple objects in a single query (using an upsert)
- Makes it easy to cache and avoid database queries
- Supports soft deletes
- Makes it easy to handle transactions in a Unit of Work
- Highly customizable
Corma doesn't:
- Autoload or lazy load relationships by default
- Do migrations or code generation
Works in MySql and PostgreSQL.
Install via Composer
Via the command line:
composer.phar require thewunder/corma ~4.0
Or add the following to the require section your composer.json:
"thewunder/corma": "~4.0"
For PHP versions < 8.0 use Corma version ~3.0
Basic Usage
Create a DataObject
namespace YourNamespace\Dataobjects; class YourDataObject { protected $id; //If the property name == column name on the table your_data_objects it will be saved protected $myColumn; //Getters and setters.. }
And a Repository (optional)
namespace YourNamespace\Dataobjects\Repository; class YourDataObjectRepository extends ObjectRepository { //Override default behavior and add custom methods... }
Create the orm and use it
$db = DriverManager::getConnection(...); //see Doctrine DBAL docs $orm = ObjectMapper::withDefaults($db, $container); //uses any PSR-11 compatible DI container $object = $orm->create(YourDataObject::class); //Call setters... $orm->save($object); //Call more setters... $orm->save($object); //Call more setters on $object... $objects = [$object]; $newObject = $orm->create(YourDataObject::class); //call setters on $newObject.. $objects[] = $newObject; $orm->saveAll($objects); //find existing object by id $existingObject = $orm->find(YourDataObject::class, 5); //find existing objects with myColumn >= 42 AND otherColumn = 1 $existingObjects = $orm->findBy(YourDataObject::class, ['myColumn >='=>42, 'otherColumn'=>1], ['sortColumn'=>'ASC']); //load relationships $orm->loadOne($existingObjects, OtherObject::class, 'otherObjectId'); $orm->loadMany($existingObjects, AnotherObject::class, 'yourObjectId'); $orm->loadManyToMany($existingObjects, DifferentObject::class, 'link_table'); //delete those $orm->deleteAll($existingObjects);
Documentation
See the wiki for full documentation.
Contributing
Please see CONTRIBUTING for details.