Lien | Doctrine | Agile Data | Eloquent | Yii ORM | Cake ORM | Fuel ORM | Red Bean PHP | Ting | Spiral ORM | .. |
---|---|---|---|---|---|---|---|---|---|---|
Site web | doctrine-project.org | git.io/ad | yiiframework.com | redbeanphp.com | ccmbg.com/... | spiral-framework.com/... | ||||
Description | Data Access Framework for high-latency databases (Cloud SQL/NoSQL). | RedBeanPHP is an easy to use ORM for PHP. It's a Zero Config ORM lib that 'automagically' builds your database schema. | Simple: no magic inside : it’s basically SQL queries | ORM engine with automatic database scaffolding, strict schemas, code discovery, modular database partitions and various relation loaders. | ||||||
Github / Bitbucket / Sourceforge | github.com/... | git.io/ad | github.com/... | github.com/... | bitbucket.org/... | github.com/... | ||||
Licence | MIT | MIT | BSD-3 | New BSD / GPL | Apache 2 | MIT | ||||
Dernière version | 2.5.5 | 1.2.x | 2.0.10 | 4.3.2 | 3.4.2 | 1.0.8 | ||||
How schema is defined? | PHP, XML, YAML | in PHP. Method init() in Model class defines fields, relations, conditions, etc. | Model class properties | Active record magic properties. | Automatically discovered on the fly. | PHP | PHP Const array. Column class. | |||
Code generation | Oui schema-tool | Oui https://github.com/atk4/schema | Oui Web and console generator https://github.com/yiisoft/yii2-gii | |||||||
Can be used in Any Framework | Oui composer / packagist | Oui Through composer/packagist | Oui Through Capsule | - Planned in 2.1.x | Oui | Oui composer / packagist | ||||
Automated Cache | Oui Frameworks focuses on optimizing queries rather then caching. Still possible with cross-persistence saving. | Oui | Oui | |||||||
Anti-patterns (purposely included) | Model close-coupled with Persistence and Field classes. | Eloquent is a God Class; Global functions; DB Conection is global; | ||||||||
Audience | ||||||||||
Dependencies | Medium: ±5 packages. | Minimal: 2 packages: DSQL Query Builder (git.io/... | Minimal: 3, pimple, doctrine/cache, aura/sqlquery | |||||||
Simplicité | aucune note | 5.0/5 2 notes | aucune note | 5.0/5 2 notes | 5.0/5 1 note | aucune note | aucune note | 5.0/5 1 note | aucune note | aucune note |
Enterprise Compliance | 5.0/5 1 note | 5.0/5 2 notes | 3.0/5 1 note | 4.5/5 2 notes | 5.0/5 1 note | aucune note | aucune note | 5.0/5 1 note | aucune note | aucune note |
Minimum PHP Version | 5.4 | 5.6 | 5.4 | 5.5 | ||||||
Basic Features | ||||||||||
PDO Support | Oui Yes | Oui Yes | Oui | Oui | - But made a custom driver to support it is easy | Oui https://spiral-framework.com/guide/database-databases | ||||
Transparent support for NoSQL | - Through 3rd party drivers. | Non Eloquent is built on Query Builder. Perhaps moloquent? Also - Through Caching backend, but not as ORM native persistence. | Oui Avialable cross sql and nosql datababase relations (https://github.com/yiisoft/yii2-mongodb) | Non Build around plain queries. | Non | Non No, through ODM (https://spiral-framework.com/guide/odm-databases) | ||||
How to invoke db-vendor-specific extensions? | Oui DBAL | Oui For SQL - save/load/delete operations are expressed in DSQL Queries that can be manipulated: http://git.io/dsql | Oui Through Query Builder / RAW queries. | Oui SQL - Query Builder. | - Can add SQL code chunks. | Oui Ting use native query, you can use everyting of your SGBD | Oui Query models: https://spiral-framework.com/guide/orm-query | |||
Array as a persistence | Oui CRUD operations supported | Oui https://github.com/yii2tech/filedb | Non | Non | ||||||
RestAPI as a persistence | - Through 3rd party extension. | - To extend BaseActiveRecord | Non | Non | ||||||
JSON string as a persistence | Oui Supported with few extra lines of code. | - To extend BaseActiveRecord | Non | Non | ||||||
Same model, multiple persistences | Oui Same class. Different object. | - (no docs) | ||||||||
Basic Single-record operations (C,R,U,D) | ||||||||||
Table Name Mapping | Oui Yes | Oui Yes | Oui Same as model class name by default | Oui Using static method of active record. http://www.yiiframework.com/doc-2.0/guide-db-active-record.html#declaring-ar-classes | Non mapping no longer supported. | Oui Yes | ||||
Field Name Mapping | Oui Yes, (Annotations in PHP) | Oui Yes (Field::actual property) | - Through accessors/3rd party extension | Oui | Non mapping no longer supported. | Oui Yes | ||||
Map Entity to SubQuery | Non Must be physical table | Oui Yes. Extension exist for UNION-models. https://github.com/atk4/report | Non Must be physical table. | - table = new Expression(..) | Non | Non This concept is no-sense for Ting | ||||
Map property to expression | Non Must be physical field | Oui $model->addExpression() | Non Must be physical table | - (couldn't find docs) | Non | Non This concept is no-sense for Ting | ||||
Map native types (DateTime) | Oui $field->type = 'date' | Oui Accessors and Mutators | Oui Active record behaviors | Oui | Oui Yes | - No support for DateTime. https://spiral-framework.com/guide/orm-accessors | ||||
User-defined types (e.g. "23 USD") | Oui Type class | Oui Yes. Independent from Model. by extending Field class. | Oui Accessors and Mutators | Oui Active record behaviors | Oui Yes, with custom serializer | |||||
Map field of related Entity ('currency' = currency_id->Model Currency.name) | - Specific record only | Oui Transparently maps into sub-select. | - Relationship, but only single record. | Oui $model->currency->name | Non | Oui Yes | ||||
Map field to sub-query on related entity (Client.balance = Client->orders->sum(total)) | Non | Oui Yes. hasMany()->addField(..aggregate) | Non | - (couldn't find docs) | Non | - This concept is no-sense for Ting | ||||
Entity to join multiple tables (adding new record populates both tables) | Oui Associations | Oui $model->join('other_table') | Non | Non No native support. | Non | Oui Yes | ||||
Criteria, Scope, Conditions (Model will refuse to work with records that does not match criteria) | ||||||||||
Support model-level criteria | Oui Yes. Applied on loading / saving / update. | - Global Scope (querying only) | Non | Non | ||||||
Soft-delete | Oui Extension | Oui Through criteria. Example given in the docs. | Oui Trait and Scope | Oui Events and behaviors | Non | |||||
Domain Model Criteria | Oui $m->addCondition('gender','M'); where 'gender' can be arbitrary expression, sub-select, field from association(join) or mapped no another physical field. | - Scopes, but not in domain model. | Non Only for specific query: User::find()->byEmail('...')->active()->one() | Non | ||||||
Expression-based condition | Oui $m->addCondition($m->expr('..')); | Oui through Query Builder | Non Only for query: User::find()->andWhere('...')->all() | Non | ||||||
Criteria Compliance (new record must match condition) | Oui Transaction rollback and exception. Automated-rloading. | Non | Non | |||||||
Dynamic criteria | Oui $user->addCondition('is_expired', false) | Non Only Querying: User::find()->where(['a' => '1', 'b' => true])->all(); | Non | |||||||
Query Building (Convert Model into Query object for further SQL tweaking) | ||||||||||
Convert Model into Query Object | Oui $q = $model->action('select'); | Oui Model is a Query object. See: Model::where() | Oui \yii\db\ActiveRecord::find() | Non | Oui RecordSelector | |||||
Raw expression | Oui new Expression('any sql') | Oui DB::raw() | Oui new \yii\db\Expression('...') | Oui | Oui | |||||
Nested/Composite Queries/Expressions | Oui Expression can be in any part of query | Non | Oui Expression can be in any part of query | Non | ||||||
Reference domain-model field in query | Oui through Expressionable interface | Non No fields. Only properties. | Non Field is class property. | Non | Non | |||||
field, where, order, limit | Oui Expressions and Parametric values | Oui | Oui \yii\db\ActiveQuery | Non | Oui | |||||
options, rollup, partition | - Through custom templates, or expressions. | - not sure. | ||||||||
UPDATE, DELETE, INSERT query building | Oui | Oui | Non | Oui | ||||||
REPLACE, TRUNCATE | Oui | - Throught raw sql in \yii\db\Command | - wipe(), | |||||||
SHOW, DESCRIBE, CALL | - Supported through Expressions or Custom query template | - Throught raw sql in \yii\db\Command | - Automatic schema alter / discovery. | |||||||
ALTER, CREATE query building | Oui Addon: http://github.com/atk4/schema | Oui | Non | |||||||
User-defined query template | Oui Templates for all queries | Oui (please link doc) | Non | |||||||
full support for OR conditions | Oui Through Object Composition and Expressions | - Partial | - | Non only raw query | ||||||
Use Domain logic in multi-record update | - Supported, but must map fields/values manually. | Non | Non | Non | ||||||
Data Fetching (different ways to retrieve data from database) | ||||||||||
Get All Data (2x array) | Oui | Oui | Oui \yii\db\Query::all() | Oui exportAll() | Oui | |||||
Associative Array (id=>value) | Non Planned | Oui lists() | ||||||||
Select only required fields | Oui | |||||||||
Typecasting (e.g. DateTime) | Oui | Oui | ||||||||
Import (multiple records) | Oui | Oui | ||||||||
Respect domain model mapping (and criteria) | Oui | |||||||||
Single row | Oui loadAny | Oui | Oui \yii\db\Query::one() | Oui | ||||||
Single Value | Oui Through action | Oui | Oui \yii\db\Query::scalar() | Oui | ||||||
Single Column | - may need to map resulting array | Oui | Oui \yii\db\Query::column() | Oui | Oui | |||||
Iterator | Oui | Oui | Oui | |||||||
Bypass persistence mapping | Oui action('select')->getAll() | Oui ?? (e..g prevent date from being transformed into Carbon) | ||||||||
Loading and Saving individual records | ||||||||||
Load by ID | Oui load(id) | Oui User::findOne(1) | Oui | Oui get(id) | Oui findByPK | |||||
Load by other field | Oui loadBy('field', $value) | Oui User::findOne(['id' => 1]) | Non | Oui getBy(['propertyName' => 'value']); | ||||||
Read-only Models | Oui Yes | Non | ||||||||
Model without primary key | Oui Yes, but only in Read-only Mode | Non | Oui | |||||||
Specify fields to load | Oui onlyFields() | Non Fields load with SELECT * | Oui User::find()->select([])->one() | Non | Oui | |||||
Save only sends dirty fields | Oui | Oui | Oui | - (there is Dirty support, so I assuming it is supported) | Oui | Oui | ||||
Guarded / Fillable properties | Oui Conditions and OnlyFields do same thing but more reliably. | Oui Prevents "create($_GET)" from messing up important fields. | ||||||||
Object Hierarchy Model | ||||||||||
Admin extends User, adds criteria (is_admin=1) | Oui Yes, recommended pattern. "User" class adds condition. | Non | Non Can be done as wrapper: User::findAdmin(..) or custom CDbCriteria | Non | ||||||
Admin extends User, adds accessible fields | Oui Yes, recommended pattern. | Non | Non | Non | ||||||
Extend model, add Join (Disjoined SubTypes) | Oui Yes. Unlimited number of joins. | Non | Non | Non | ||||||
Extend model change table | Oui Yes. Used to tweak 3rd party models. | Non | ||||||||
Relations/References (One model can relate to another model. NOT A TABLE JOIN) | ||||||||||
Model can define relation to other Model | Oui References are implemented as Objects | Oui Relations | Oui Relations | Oui | ||||||
One-to-Many | Oui $user->hasMany('Orders', new Order()); | Oui | Oui | |||||||
One-to-many traversal strategy | Returns destination model instance with dynamically applied criteria (parent_id=123). No queries are executed. Inserting record into this model will ensure association with parent model. | Returns array of objects that may either be pre-loaded with record data or only contain IDs (lazy-loaded). | Uses classical eager/lazy loading approach. with() can help pre-fetch the data for related entities. | pre-fetch and store objects in an array. | ||||||
Lazy/Eager-loading | Non Anti-pattern | Oui | Oui | Oui | ||||||
One-to-One | Oui $order->hasOne('user_id', new User()); | Oui | Oui | |||||||
Many-to-Many | Oui $user->addCondition('vip', true)->ref('Orders'); | Oui relations() method of an entity can define. | ||||||||
Deep Many-to-Many traversal. | Non | Oui $user->ref('Orders')->ref('Payments')->action('count'); No intermediate queries. | - only with "to-one" references: $book->author->address->street; Executes multiple queries. | - only with to-one references. Executes multiple queries. | ||||||
Cross-Persistence traversal | Oui $user->hasMany('Log', new Log($mongodb)); | - No docs. | Non | |||||||
Cross-persistence joins, aggregation, reporting | ||||||||||
Multi-persistence join | Non | Non | Non | Non | ||||||
UNION existing models | Non | Oui Yes, in add-on https://github.com/atk4/report/. Can join UNION result with more tables. | Non | Non | ||||||
Domain-model Aggregation | Oui Group by multiple fields. Apply aggregation functions. Preserve types. | Non | ||||||||
Model to Model join | Non Planned. | Non | ||||||||
Multi-persistence UNION | Non | Non | Non | Non | ||||||
Behaviours / Hooks | ||||||||||
Before/After operation | Oui | Oui | ||||||||
Override standard C,R,U,D operations | Oui | Oui | ||||||||
Persistence-specific hooks (to modify Query) | Oui | - (no docs) | ||||||||
User-defined hooks | Oui | Oui | ||||||||
Auditing | ||||||||||
Global Auditing | Oui http://www.agiletoolkit.org/data/extensions/audit | Non | ||||||||
Store old/new field values | Oui Yes in JSON and user-readable string. | Oui | ||||||||
Revert action (undo) and replay (redo) | Oui | Non | Non | |||||||
Reactive actions | Oui Each action will be automatically linked with sub-actions which may be invoked through Hooks. | |||||||||
Store log in any persistence | Oui | Non | ||||||||
Override, Add fields to audit log | Record dirty fields before persisting. Type-cast into JSON string and store in a single field of AuditLog Model. This model can be persisted anywhere, table, file, etc. | |||||||||
Custom events | Oui | Oui | ||||||||
Access to record-specific history | Oui $item->ref('AuditLog'); | - Through a custom query. | ||||||||
Date of creation, modification | - No but easy to add through hook. | Oui \yii\behaviors\TimestampBehavior | Oui TimestampTrait | |||||||
User/IP creation, modification | - Easy to add through a hook. | Oui \yii\behaviors\BlameableBehavior | ||||||||
Store incremental revisions | - Easy to add through a hook | Oui | ||||||||
Integration | ||||||||||
Field meta-information provided | Type, caption, possible values, mapped field, join table spec, encryption, serialization, UI-specific settings, validation rules. | |||||||||
UI extensions | Non | Oui CRUD, Form, Table, Grid, Entity-manager. (see https://github.com/atk4/ad) | Non | Non | Non | |||||
API extensions | Oui RestFULL API, automated CRUD operations + RPC https://github.com/atk4/api | |||||||||
J'aime | J'aime 0 | J'aime 3 | J'aime 0 | J'aime 1 | J'aime 1 | J'aime 0 | J'aime 0 | J'aime 0 | J'aime 0 | J'aime 0 |