2010/10/28
Introducing DumbledORM,
a novelty ORM
I'm proud to release DumbledORM today. It is the product of a late night hack sesh with an idea to build a PHP ORM in less than 100 lines. After it's all said and done I arrived at 200 lines with lots of features. The decision to call it DumbledORM came after realizing there was more casting and magic in it than anything out there. :)
Some examples of what it can do:
# load record with id 13
$user = new User(13);
$user->setName('Jason')->save();
# create new record
$user = new User(array(
'name' => 'Jason',
'email' => 'a@b.com',
));
$user->save();
# find single record
User::one(array('name' => 'Jason'))->delete();
# apply object methods to entire set at once
PhoneNumber::select('`number` like "607%"')
->setLocation('Ithaca, NY')
->save();
# relations between objects
$user->create(new PhoneNumber(array(
'type' => 'home',
'number' => '347-333-4444',
)))->save();
# update all user phone numbers matching $type
$user->getPhoneNumber('`type` = ?',$type)
->setType($new_type)
->save();
Applying model object methods to entire sets of objects, jQuery style, is made possible by this incantation:
final class ResultSet extends ArrayIterator {
public function __call($method,$params=array()) {
foreach ($this as $obj) {
call_user_func_array(array($obj,$method),$params);
}
return $this;
}
}
So proud. I hope you find it fun and maybe even useful. Although at this point all I can say is that it's passing it's little tests.