Convention-based Object-Relational Mapper

Related tags

Database php orm database
Overview

Corma

Latest Version on Packagist Software License Build Status Coverage Status SensioLabsInsight

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 ~3.0

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

"thewunder/corma": "~3.0"

For PHP version > 5.5 < 7.1 use Corma version ~2.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);

$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.

You might also like...
A simple PHP and MySQL based internet forum that displays the messages in classical threaded view (tree structure)

my little forum my little forum is a simple PHP and MySQL based internet forum that displays the messages in classical threaded view (tree structure).

Laravel Code Generator based on MySQL Database

Laravel Code Generator Do you have a well structed database and you want to make a Laravel Application on top of it. By using this tools you can gener

Pure PHP NoSQL database with no dependency. Flat file, JSON based document database.
Pure PHP NoSQL database with no dependency. Flat file, JSON based document database.

Please give it a Star if you like the project 🎉 ❤️ SleekDB - A NoSQL Database made using PHP Full documentation: https://sleekdb.github.io/ SleekDB i

Tiny php mysql lib (PDO-based) with handy fetch/update functionality, supports both SQL and parametric queries

Micro PHP mysql lib (~ 200 lines of code) with ultra powerful CRUD for faster than ever development: parametric fetch/insert/update/delete (based on a

phpSleekDBAdmin - a web-based SleekDB database admin tool written in PHP
phpSleekDBAdmin - a web-based SleekDB database admin tool written in PHP

phpSleekDBAdmin is a web-based SleekDB database admin tool written in PHP. Following in the spirit of the flat-file system used by SleekDB, phpSleekDBAdmin consists of a single source file, phpsleekdbadmin.php. The interface and user experience is comparable to that of phpLiteAdmin and phpMyAdmin.

Migrations for MongoDB based on PHPMongo ODM

PHPMongo Migrator Migrations for MongoDB based on PHPMongo ODM Schema not required in MongoDb, so we dont need to create databases, collections or alt

Doctrine Object Relational Mapper (ORM)

3.0.x 2.9.x 2.8.x Doctrine 2 is an object-relational mapper (ORM) for PHP 7.1+ that provides transparent persistence for PHP objects. It sits on top o

A lightweight nearly-zero-configuration object-relational mapper and fluent query builder for PHP5.

Idiorm http://j4mie.github.com/idiormandparis/ Feature/API complete Idiorm is now considered to be feature complete as of version 1.5.0. Whilst it wil

[READ-ONLY] A flexible, lightweight and powerful Object-Relational Mapper for PHP, implemented using the DataMapper pattern. This repo is a split of the main code that can be found in https://github.com/cakephp/cakephp

CakePHP ORM The CakePHP ORM provides a powerful and flexible way to work with relational databases. Using a datamapper pattern the ORM allows you to m

Propel2 is an open-source high-performance Object-Relational Mapping (ORM) for modern PHP

Propel2 Propel2 is an open-source Object-Relational Mapping (ORM) for PHP. Requirements Propel uses the following Symfony Components: Config Console F

A simple object-relational mapping library built using PHP.

A simple object-relational mapping library built using PHP.

Small convention based CQRS library for PHP

LiteCQRS for PHP Small naming-convention based CQRS library for PHP (loosely based on LiteCQRS for C#) that relies on the MessageBus, Command, EventSo

Convention based routing for PHP

Croute Convention based routing for PHP based on Symfony components. Croute is great because: You don't need to maintain a routing table Promotes cons

Another web-based convention scheduling system

Convention scheduling tool originally developed for Arisia. Now used by several other conventions. PlanZ tracks sessions (events, panels, and anything that needs to be scheduled), participants, and rooms. PlanZ was originally Zambia, but many changes have been made away from the original code and so a new name was desired.

Task for GrumPHP that adds CSS linting support with stylelint. An easy way to enforce convention and avoid errors in your styles

grumphp-stylelint-task Installation Stylelint is a static analysis tool for styles. A mighty, modern linter that helps you avoid errors and enforce co

A micro web application providing a REST API on top of any relational database, using Silex and Doctrine DBAL

Microrest is a Silex provider to setting up a REST API on top of a relational database, based on a YAML (RAML) configuration file.

Relational Metrics - lararvel package help you to make your metrics easier
Relational Metrics - lararvel package help you to make your metrics easier

Relational Metrics This package will help you to make your metrics easier, You could get metrics about your Models, Models depending on their relation

A data mapper implementation for your persistence model in PHP.

Atlas.Orm Atlas is a data mapper implementation for persistence models (not domain models). As such, Atlas uses the term "record" to indicate that its

Plastic is an Elasticsearch ODM and mapper for Laravel. It renders the developer experience more enjoyable while using Elasticsearch, by providing a fluent syntax for mapping, querying, and storing eloquent models.
Plastic is an Elasticsearch ODM and mapper for Laravel. It renders the developer experience more enjoyable while using Elasticsearch, by providing a fluent syntax for mapping, querying, and storing eloquent models.

Plastic is an Elasticsearch ODM and mapper for Laravel. It renders the developer experience more enjoyable while using Elasticsearch, by providing a f

Comments
  • No JSON type support

    No JSON type support

    Doctrine\DBAL\DBALException: Unknown database type json requested, Doctrine\DBAL\Platforms\MySqlPlatform may not support it. in /home/scott/projects/lifestyle-crm/vendor/doctrine/dbal/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php on line 429 Call Stack: 0.0631 367096 1. {main}() /home/scott/projects/lifestyle-crm/web/index.php:0 0.1388 2434912 2. Croute\Router->route(???) /home/scott/projects/lifestyle-crm/web/index.php:11 0.1400 2521224 3. Croute\Router->invokeAction(???, ???, ???, ???) /home/scott/projects/lifestyle-crm/vendor/thewunder/croute/src/Router.php:232 0.1604 3066752 4. Lifestyle\Controller\ErrorHandler->handleException(???) /home/scott/projects/lifestyle-crm/vendor/thewunder/croute/src/Router.php:311

    enhancement help wanted 
    opened by samuraiseoul 0
Owner
Michael O'Connell
Michael O'Connell
A lightweight nearly-zero-configuration object-relational mapper and fluent query builder for PHP5.

Idiorm http://j4mie.github.com/idiormandparis/ Feature/API complete Idiorm is now considered to be feature complete as of version 1.5.0. Whilst it wil

Jamie Matthews 2k Dec 27, 2022
[READ-ONLY] A flexible, lightweight and powerful Object-Relational Mapper for PHP, implemented using the DataMapper pattern. This repo is a split of the main code that can be found in https://github.com/cakephp/cakephp

CakePHP ORM The CakePHP ORM provides a powerful and flexible way to work with relational databases. Using a datamapper pattern the ORM allows you to m

CakePHP 146 Sep 28, 2022
Propel2 is an open-source high-performance Object-Relational Mapping (ORM) for modern PHP

Propel2 Propel2 is an open-source Object-Relational Mapping (ORM) for PHP. Requirements Propel uses the following Symfony Components: Config Console F

Propel 1.2k Dec 27, 2022
A data mapper implementation for your persistence model in PHP.

Atlas.Orm Atlas is a data mapper implementation for persistence models (not domain models). As such, Atlas uses the term "record" to indicate that its

null 427 Dec 30, 2022
Analogue ORM : Data Mapper ORM for Laravel/PHP

(this project is looking for a new maintainer) Analogue ORM Analogue is a flexible, easy-to-use ORM for PHP. It is a transposition of the Eloquent ORM

Analogue ORM 632 Dec 13, 2022
Articulate - An alternative ORM for Laravel, making use of the data mapper pattern

Articulate Laravel: 8.* PHP: 8.* License: MIT Author: Ollie Read Author Homepage: https://ollie.codes Articulate is an alternative ORM for Laravel bas

Ollie Codes 4 Jan 4, 2022
A simple PHP library to transfer data from a source (object or array) to an object.

SimplexMapper A simple PHP library to transfer data from a source (object or array) to an object. $dbData = [ 'username' => 'pfazzi', 'emailAd

Patrick Luca Fazzi 4 Sep 22, 2022
PHP Object Model Manager for Postgresql

POMM: The PHP Object Model Manager for Postgresql Note This is the 1,x version of Pomm. This package is not maintained anymore, the stable Pomm 2.0 is

Grégoire HUBERT 161 Oct 17, 2022
A MongoDB based Eloquent model and Query builder for Laravel (Moloquent)

Laravel MongoDB This package adds functionalities to the Eloquent model and Query builder for MongoDB, using the original Laravel API. This library ex

Jens Segers 6.3k Jan 5, 2023
A Redis based, fully automated and scalable database cache layer for Laravel

Lada Cache A Redis based, fully automated and scalable database cache layer for Laravel Contributors wanted! Have a look at the open issues and send m

Matt 501 Dec 30, 2022