For the Kohana Framework.
NOTICE: THIS IS PRE-ALPHA CODE... nothing much works yet...
This is an entirely new Object-Relational Mapping Framework that uses both Active Record and Data Mapper Patterns.
This library is mostly new code, but some ideas, functions, and possibly source code may have been borrowed from similar libraries (ORM, Sprig, Jelly)
Credit and thanks goes out to those authors.
Goals:
- Simple and intuitive to use, joins are automatic, SQL is hidden
- Object Aggregation for a Modular Model Framework that is Highly Extensible
- Data source agnostic (SQL, NoSQL, FQL, YQL, XML, JSON)
- Record level and Collection level modifications
- Minimal and efficient data retrieval and caching
- Composite/Polymophic Keys
- Calculated Fields
- Standard One-to-One, Many-to-One, Many-to-Many Relationships
- Hierarchical Relationships (Adjacency List, MPTT, Transitive Closure)
- Customizable Inputs & Forms
- Scaffolding system
- More... As I think of them...
Examples:
-
Get the first 20 user objects with a name that starts with 'Bob'.
$users = Yada::factory('User'); $users->name->like('Bob%'); $users->load(20);
-
Get the next 10 user objects
$users->load(10,20);
-
Change their name to Robert.
$users->name->replace('Bob', 'Robert'); $users->save();
-
Or iterate through them one at a time.
foreach($users as $user) { $user->name->replace('Bob', 'Robert'); // Update them individually $user->save(); } // Or make changes then update as a set; $users->save();
-
Modify sets of records without iterating
$products = Yada::factory('Product'); $products->name->replace('exmple', 'example') $products->name->like('%exmple%') $products->save();
-
Create new records
$product = Yada::factory('Product'); // With normal assignment statements $product->name = 'Gizmo'; $product->price = 20; // ...or by passing an associative array $product->values(array('name'=>'Gizmo', 'price' => 20)); // ...or with method chaining $product->name->set('Gizmo')->price->set(20); // Save the record. $product->save();
More examples to come....