Giter Club home page Giter Club logo

corma's Introduction

Build Status Coverage Status SensioLabsInsight

Corma

Corma is a high-performance, convention-based ORM based on Doctrine DBAL.

Croute is great because:

  • No complex and difficult to verify annotations or configuration files
  • Promotes consistent code organization
  • Allows for customization through symfony events
  • Supports soft deletes
  • Can save multiple objects in a single query (using an upsert)
  • Makes it easy to cache and avoid database queries
  • Loads one-to-many and many-to-many relationships with a method call

Corma doesn't:

  • Autoload or lazy load anything
  • Have any knowledge of relationships between objects
  • Have any Unit of Work concept, everything is executed right away
  • Do migrations or code generation

Don't use this in production, things will change.

Only tested on MySQL.

Install via Composer

Via the command line:

composer.phar require thewunder/corma *

Or add the following to the require section your composer.json:

"thewunder/corma": "*"

Basic Usage

Create a DataObject

namespace YourNamespace\Dataobjects;

class YourDataObject extends DataObject {
    //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 DataObjectRepository {
    //Override default behavior and add custom methods...
}

Create the orm and use it

$db = DriverManager::getConnection(...); //see Doctrine DBAL docs
$orm = ObjectMapper::create($db, new EventDispatcher(), ['YourNamespace\\Dataobjects']);

$object = $orm->createObject(YourDataObject::class);
//Call setters...
$orm->save($object);
//Call more setters...
$orm->save($object);

//Call more setters on $object...
$objects = [$object];
$newObject = $orm->createObject(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->loadOneToMany($existingObjects, OtherObject::class, 'otherObjectId');
$orm->loadManyToMany($existingObjects, DifferentObject::class, 'link_table');

//delete those
$orm->deleteAll($existingObjects);

Events

Symfony events are dispatched for every stage of the object lifecycle. ObjectName here is the class without namespace.

  1. DataObject.beforeSave
  2. DataObject.{ObjectName}.beforeSave
  3. DataObject.beforeInsert
  4. DataObject.{ObjectName}.beforeInsert
  5. DataObject.beforeUpdate
  6. DataObject.{ObjectName}.beforeUpdate
  7. DataObject.afterSave
  8. DataObject.{ObjectName}.afterSave
  9. DataObject.afterInsert
  10. DataObject.{ObjectName}.afterInsert
  11. DataObject.afterUpdate
  12. DataObject.{ObjectName}.afterUpdate
  13. DataObject.beforeDelete
  14. DataObject.{ObjectName}.beforeDelete
  15. DataObject.afterDelete
  16. DataObject.{ObjectName}.afterDelete

corma's People

Contributors

thewunder avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.