Agile Data

Produits
2016-10-24 17:38:10
PHP Framework for better Business Logic design and scalable database access
PHP Data Access Libraries (ORM, ActiveRecord, Persistence)
Agile Data
Site webhttp://agiletoolkit.org/data
Github / Bitbucket / Sourceforgehttp://git.io/ad
LicenceMIT
Dernière version1.1.x
How schema is defined?method init() in Model class defines fields, relations, conditions, etc.
Code generation- Planned.
Can be used in Any FrameworkOui Through composer/packagist
Automated Cache- Planned
Anti-patterns (purposely included)SRP in Model. Implements Scopes and Active Record.
Audience
DependenciesMinimal: 2 packages: DSQL Query Builder (http://git.io/dsql)
Simplicité5.0 2 notes
Enterprise Compliance5.0 2 notes
Minimum PHP Version5.6
Basic Features
PDO SupportOui MySQL, SQLite, Others
NoSQL Integrate Transparently- Supported, but drivers not provided.
How to invoke db-vendor-specific extensions?Oui Provides access to persistence-layer actions (Queries)
Array as a persistenceOui CRUD operations supported
RestAPI as a persistence- Planned
JSON string as a persistence- In development
Same model, multiple persistencesOui Same class. Different object.
Persistence Mapping (must support C,R,U,D)
Table Name MappingOui $model->table = 'my_table'
Field Name MappingOui PHP: "name" = SQL: "first_name"
Map Entity to SubQueryOui "Table" can be "Expression" (or another Model)
Map property to expressionOui $model->addExpression()
Map native types (DateTime)Oui $field->type = 'date'
User-defined types (e.g. "23 USD")Oui Through typecasting
Map field of related Entity ('currency' = currency_id->Model Currency.name)Oui Maps into sub-query.
Map field to sub-query on related entity (Client.balance = Client->orders->sum(total))Oui hasMany()->addField(..aggregate)
Entity to join multiple tables (adding new record populates both tables)Oui $model->join('other_table')
NoSQL (must be transparent to domain logic)
MongoDB support- Planned
Neo4j- Planned
MemCache- Planned
Criteria, Scope, Conditions (Model will refuse to work with records that does not match criteria)
Support model-level criteriaOui
Soft-delete- Easy to implement through conditions. See docs.
Domain Model CriteriaOui $m->addCondition('gender','M')
Expression-based conditionOui $m->addCondition($m->expr('..'));
Criteria Compliance (new record must match condition)Oui With reloading and rollback
Dynamic criteriaOui $user->addCondition('is_expired', false)
Query Building (Convert Model into Query object for further SQL tweaking)
Convert Model into Query ObjectOui $q = $model->action('select');
Raw expressionOui new Expression('any sql')
Nested/Composite Queries/ExpressionsOui Expression can be in any part of query
Reference domain-model field in queryOui through Expressionable interface
field, where, order, limitOui Expressions and Parametric values
options, rollup, partition- Through custom templates, or expressions.
UPDATE, DELETE, INSERT query buildingOui
REPLACE, TRUNCATEOui
SHOW, DESCRIBE, CALL- Supported through Expressions or Custom query template
ALTER, CREATE query buildingOui Addon: http://github.com/atk4/schema
User-defined query templateOui Templates for all queries
OR deep nested conditionsOui Through Object Composition
Use Domain logic in multi-record update- Supported, but must map fields/values manually.
Data Fetching (different ways to retrieve data from database)
Get All Data (2x array)Oui
Associative Array (id=>value)Non Planned
Single rowOui loadAny
Single Value- Through action
Single ColumnNon Planned
IteratorOui
Bypass persistence mappingOui action('select')->getAll()
Loading and Saving individual records
Load by IDOui load(id)
Load by other fieldOui loadBy('field', $value)
Load if expressionOui loadBy($expression)
Load respects Scope (model-level condition)Oui All conditions added as "where" clause
Specify fields to loadOui onlyFields()
Save only sends dirty fieldsOui
Guarded / Fillable properties- Conditions and OnlyFields do same thing differently.
Object Hierarchy Model
Admin extends User (is_admin=1)Oui Yes, recommended pattern. "User" class adds condition.
Model that represent Orders of single User.Oui Yes, recommended pattern.
Extend model, add Join (Disjoined SubTypes)Oui Yes. Unlimited number of joins.
Extend model change tableOui Yes. Used to tweak 3rd party models.
Relations/References (One model can relate to another model. NOT A TABLE JOIN)
Model can define relation to other ModelOui References are implemented as Objects
One-to-ManyOui $user->hasMany('Orders', new Order());
One-to-many traversal strategyReturns 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.
Lazy/Eager-loadingNon Anti-pattern
One-to-OneOui $order->hasOne('user_id', new User());
Many-to-ManyOui $user->addCondition('vip', true)->ref('Orders');
Deep Many-to-Many traversal.Oui $user->ref('Orders')->ref('Payments')->action('count'); No intermediate queries.
Cross-Persistence traversalOui $user->hasMany('Log', new Log($mongodb));
Multi-persistence Mapping (some data from SQL, others MongoDB)
Multi-persistence join- Planned.
UNION existing models- Planned
Multi-persistence UNIONNon But you can merge raw data
Multi-persistence value linking (current_sensor_value)- Through 'afterLoad' hook.
Behaviours / Hooks
Before/After operationOui
Hooks for C,R,U,D operationsOui
Persistence-specific hooks (to modify Query)Oui
User-defined hooksOui
Auditing
ExtensionOui http://www.agiletoolkit.org/data/extensions/audit
Mapping strategyRecord 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.
How to set-upAuditLog can be enabled for all models associated with a specific persistence. No further changes are necessary. Works out of the box.
Store old/new field valuesOui Yes in JSON and user-readable string.
Date of creation, modification- No but easy to add through hook.
User/IP creation, modification- Easy to add through a hook.
Store incremental revisions- Easy to add through a hook
Revert action (undo)Oui
Custom eventsOui
Custom fields, tableOui Remove default fields, use your own table, fields, formats.
Store in CSV- Planned
Access to record-specific historyOui $item->ref('AuditLog');
Access Control
Implementation StrategyDefine a special DB-hook. Every time new "Model" is initialized, extra "condition" will be added. This will make sure that you won't forget some important condition when traversing references. You can also restrict access to edit/delete through per-model hooks that can be globally set.
Single-system global access scopeOui Define "system_id" for all models that have this field defined - this will create global condition for all models making sure that user can work with records of one system at a time.
Meta-information (allows exploration by UI widgets)
Implementation StrategyAgile Data is designed to work with UI toolkits. Generic widgets can explore model fields and various meta-information about those fields. References are easy to identify and traverse allowing DropDown fields to populate values inside select.
UI Widget can fetch list of Model FieldsOui
UI Widget can get Field type, default value, caption, hintOui
field storing reference to another Model can map into DropDownOui Widget can discover references and traverse to fetch list of drop-down options. Model defines "title_field" which is used by default.
J'aime 2
  • 2016-10-18 22:11:55
    2016-10-24 17:38:10
  • Produits
    English
  • Publique
    Publique
  • Creative Commons License CC-BY-SA 3.0 / GNU FDL

Commentaires

  • a voté pour ce Elément (J'aime)
    Couldn't work on any other framework/orm after switching to ATK. Its just how every programmer always wanted ...
    English Posté 2016-10-25 19:16:29 par Gowrav
  • a noté ce Elément: Enterprise Compliance 5
    Using in Recent modules of our ERP
    English Posté 2016-10-25 18:51:02 par Gowrav
  • a noté ce Elément: Simplicité 5
    Most simple among what I used (almost all popular ones)
    English Posté 2016-10-25 18:50:37 par Gowrav
  • a voté pour ce Elément (J'aime)
    Not really an ORM, but offers much more powerful support for Domain Model.
    English Posté 2016-10-24 02:18:39 par Romans Malinovskis
  • a noté ce Elément: Enterprise Compliance 5
    Posté 2016-10-18 22:34:27 par Romans Malinovskis
  • a noté ce Elément: Simplicité 5
    Posté 2016-10-18 22:14:01 par Romans Malinovskis

Laisser un commentaire

Créer des tableaux comparatifs ou listes sur tout !

C'est gratuit et rapide de créer des tableaux originaux

Créer un tableau