Page 1 of 1

Zero-Configuration ORM Library

Posted: Tue Apr 21, 2009 11:20 pm
by LilMikey
* Moved to Code Critique as this is a functioning library presented for review *

Hey guys, first of all, I know I'm a noob so pardon me if this is in the wrong place or what-not.

The short story

I've released an early alpha version of a php/mysql ORM library. It supports what you'd expect, tables as objects with basic CRUD functionality, it respects relations, etc. It also has a pretty advanced query building interface that works hand in hand with the table objects. The coolest part is there is no configuration outside of providing mysql connection information. Samples and download are here: http://lilmikey.com/?page_id=274.

The long story

My contracts expired and I needed a project. I really liked the ease of use SubSonic for .NET offered and wanted something like that for php. The ORMs I toyed with in php required a bit of setup and a lot of source. All I wanted was a quick, easy library that I could drop in to any project without jumping through hoops. So I wrote it in SubSonic's image.

The library uses MySQL DDL queries to load schema information at run time. It only loads the schema as its requested and its cached for future use. That schema information drives generic row classes that provide the CRUD functionality. Getters, setters, and relations are handled through the blind function __call with validation against the schema. You get the validation and features of most common ORMs with none of the setup and configuration. Object instantiation is handled through a factory class that supports multiple named library instances (although that's far from adequately tested).

I've run it through the wringer using a number of test cases and the sample script included in the library hits most of the common bases. This is still very very early software and a lot needs to be done: sql parameterization and safety, better error reporting and handling, binary fields, just to name a few.

If there is interest in this project I'd be happy to continue working on it (however I hopefully have new paying work coming in soon) and if others want to spend time on it I can move it over to sourceforge.

Until then, it lives over here: http://lilmikey.com/?page_id=274

Thanks for your time and all feedback is appreciated.
Mike

Re: Zero-Configuration ORM Library

Posted: Wed Apr 22, 2009 1:25 am
by Christopher
The page you link to does not have anything about your library on it. It seems to have some errors.

Re: Zero-Configuration ORM Library

Posted: Wed Apr 22, 2009 7:20 am
by max529
yea...me too also cannot find your library in that page...

in the mean time, i was wondering if you could check out an ORM tool I wrote titled ,A Shorthand Notation for SQL for Lazy ppl

here is the link viewtopic.php?f=50&t=98002 ....

Thanks...

Re: Zero-Configuration ORM Library

Posted: Wed Apr 22, 2009 7:31 am
by LilMikey
Sorry guys, forgot to publish it. Looked fine logged in as admin. Should be rolling now.

Thanks,
Mike

Re: Zero-Configuration ORM Library

Posted: Wed Apr 22, 2009 8:20 am
by LilMikey
max529 wrote:yea...me too also cannot find your library in that page...

in the mean time, i was wondering if you could check out an ORM tool I wrote titled ,A Shorthand Notation for SQL for Lazy ppl

here is the link viewtopic.php?f=50&t=98002 ....

Thanks...
Hey max529, I have a feeling responses to my library might be similar to yours since the aim of both of ours is somewhat similar. So I guess this is a small defense of ORM/DAL tools in general. To me, the biggest annoyance in any project, especially small to medium size projects, is writing the DAL; repetitive get/set/save/load statements with almost identical sql in each of dozens of classes that do little besides handle putting stuff in to and sucking it out of databases. Heck, usually with smaller projects I find myself dropping the DAL altogether just sprinkling SQL to and fro which is a debugging and maintenance nightmare. With the popularity of ActiveRecord and so much time and effort being put into technologies such as Doctrine, Hibernate, linq, LLBLGen, SubSonic, etc, I'm assuming I'm not alone.

Yes, you could produce the sql statements required to perform any one feature for any one table far quicker than you could integrate our libraries but producing the sql statements to implement all of the features for all of the tables is whole other ballgame. As far as maintainability, we're offering a single centralized location for all sql and only a handful of methods that do need to be updated if sql standards change, a bug is found, or a new database is selected. No library will be able to completely replace sql but hopefully with libraries like these we can spend our time on reasonably complicated sql instead of writing hundreds of trivial statements in the CRUD-abstraction methods of our DAL.

Mike

Re: Zero-Configuration ORM Library

Posted: Wed Apr 22, 2009 11:37 am
by Christopher
LilMikey wrote:
max529 wrote:yea...me too also cannot find your library in that page...

in the mean time, i was wondering if you could check out an ORM tool I wrote titled ,A Shorthand Notation for SQL for Lazy ppl

here is the link viewtopic.php?f=50&t=98002 ....

Thanks...
Hey max529, I have a feeling responses to my library might be similar to yours since the aim of both of ours is somewhat similar. So I guess this is a small defense of ORM/DAL tools in general.
Since you are both proponents of this type of library, I think the most expert reviews would be if you used each other's code on a real project. I know max529 has suggested that using a existing library of this type is of great benefit. I assume that LilMikey is presenting this library because he thinks it could also be of real benefit to others. So you are both proponents of using pre-written code libraries. And since you both have detailed knowledge about designing this type of library, you could provide insightful reviews into the specific features, capabilities and benefits of each.

Re: Zero-Configuration ORM Library

Posted: Wed Apr 22, 2009 11:57 pm
by max529
I have gone through your description of your library.You use the following lines into the table

Code: Select all

$project = EARFactory::Table("Project")->RowBuffer();       
$project->SetName("PROJECT NAME");                                 
$project->SetClientID(1);                                          
$project->Save();   
 
But arent there a lot of libraries out there ,that uses the same procedures for inserting the data.I think Doctrine uses a simlar
syntax.

Please tell me,Have you downloaded and gone through the documentation of the class I have written?
If you use it a row can be inserted in `project` table inthe following manner.

Code: Select all

               $db->project=array('name'=>'Project Name','client_id'=>1);
That line inserts a new row into the table.

When updating and selecting based on primary key,i see you have made it not necessary to specify the filed name..
that is nice,but there is an issue of primary key on multiple fields(thanks to pickle).

to select a single row using primary key field using your class will be

Code: Select all

 
               $task = EARFactory::Table("Task")->RowBuffer()->Load(1);
               echo "ID: " . $task->GetID() . "<BR>";


same operation using my class will be

Code: Select all

            echo $db->Task(1)->ID;
for updating you have given

Code: Select all

    $task = EARFactory::Table("Task")->RowBuffer()->Load(1);    
    $task->SetDescription("NEW DESCRIPTION");           
    $task->Save(); 

using my class will be

Code: Select all

           $db->Task(1)->Description="NEW DESCRIPTION";
The problem with the kind of syntax you are using ,as i see, will be that it still requires you to type in as many charecters as when you are using a normal mysql functions.There is also many function names to learn.

I think my syntax too got some problem..that i cannot see.Can you please help me find out..LilMikey.

Re: Zero-Configuration ORM Library

Posted: Fri Apr 24, 2009 2:11 pm
by Christopher
A very nice and detailed critique. Thanks. Hopefully LilMikey can respond to the above and has comments about your library.