Re: Re: Recommended ORM for PHP

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello,

on 02/08/2008 11:51 AM Zoltán Németh said the following:
>> Metabase also generates a separate class for installing or upgrading
>> your database schema. If you change the definition of you objects, you
>> just need to call that class to install, upgrade, downgrade your
>> database schemas, safely without loosing any data that was already in
>> the database.
>>
>> This is something very secure, as it does not do any schema changes if
>> the underlying database does not support certain things you want to
>> change. If you ask for a change that is not possible, it simply fails
>> without changing anything. It is not that error prone migrations method
>> of Ruby on Rails, that you have to write "SQL" manually to do your
>> migrations, and if you made a mistake, your database data is lost.
>>
>>
> 
> schema versioning is cool, AFAIK it is missing from propel but of course
> it can transform your schema without data loss.

What I meant is that when you upgrade the database schema to reflect the
changes in your object models, Metabase performs the database schema
alterations without destroying the data previously inserted in the
database tables.


>>>> For instance, if you want to send a newsletter to a million subscribers
>>>> and you just need the e-mail address and names of the subscribers, you
>>>> can tell Metastorage to generate a report class that queries the users
>>>> objects and retrives just the name and e-mail address. The report
>>>> classes return arrays just like plain SELECT queries.
>>>>
>>>> If you use the Propel approach you would need to retrieve 1 million
>>>> objects of the users class just to pick the name and e-mail address,
>>>> which is totally inefficient in terms of memory and very slow.
>>> not at all. you can build the criteria for the select and then run a
>>> doSelectRS method which gives you only the result set in an array, no
>>> objects involved.
>> That is not exactly what I am talking about. Metastorage has an Object
>> Query Language (OQL) that lets you express whatever query conditions you
>> want. It generates PHP code with the necessary SQL queries you need. You
>> do not have to build any queries programatically at run-time.
> 
> in propel you do not touch SQL too ;)
> you initialize an object of class Criteria and define whatever you want.
> e.g.
> $c = new Criteria();
> $c->add('whatevercolumn', 'whatevervalue');
> 
> of course it can do much more, joins and everything you may need

The way I see it, this is not better than writing SQL manually. Actually
you become less productive because you need to learn a new syntax for
composing conditions without any benefits.

With Metastorage you can compose query conditions expressed in the OQL
(Object Query Language). The OQL expressions are compiled into SQL
expressions at compile time.

The big difference is that if you have a mistake in your conditions,
Metastorage tells you right away so you can fix it way before you ever
try your code at run time.

For instance, there is no way you can compare by mistake a object
identifier (primary key) with a regular integer variable because it
would not make sense, despite in SQL that is an acceptable key.

This way you generate more reliable code and you take less time to
detect and fix bugs as that happens before you ever run the generated code.

Another thing is that Metastorage OQL is really object oriented, as
opposed to relational oriented. This means that you can for instance ask
to retrieve objects that belong to collection of objects established by
a relationship between classes.

In the relational world you would do joins. That may be simple in many
cases, but if you need to deal with many-to-many relationships, you can
easily get buried in the complexity of mapping such kind of
relationships to the relational world.

Metastorage makes that much easy. You just tell that a class may contain
a collection of objects of another class, and that other class may
contain a collection of the first class.

>From that Metastorage takes care of generating a schema that includes
the intermediate database table that is necessary to establish the
many-to-many relationship.

Also in the OQL you can use operators such as  "in colllection" or "not
in collection" and Metastorage will generate an SQL expression that
includes all the right joins, so you do not get buried in the details of
doing that right manually.


>>>> There are more differences between Metastorage and Propel (and probably
>>>> others approach). I just wanted to make the point that the fact that
>>>> approaches use generated code, it does not mean that all provide the
>>>> same efficiency.
>>> yeah, sure. however there is a payoff between efficiency and portability
>>> and maintainability, and of course not all these orms have the same
>>> level of these. choose the one that fits your needs best.
>> Exactly. I choose to develop my own because nothing that existed in PHP
>> matched my needs and code quality code requirements. Of course doing it
>> yourself is an expensive measure because it takes time and skill to
>> reach a mature solution. I have been developing Metastorage for 6 years.
>> It is very mature and reliable, but there is always room for improvement.
> 
> I too had thought about implementing my own ORM, because none of them
> fits my needs exactly, however I don't have the time for that... so I
> use whatever I find the best at the moment.

Sure. Propel already existed when I started Metastorage. Although it was
better than other few existing PHP solutions, it did not satisfy me the
way it worked, as it seem still too tied to the relational world and I
did not feel that approach could bring me enough productivity, so I
could just concentrate my application models, rather than database tables.

Also the fact that it required a run-time with fat base classes to do
the basic ORM operations made me think that there should be a better way
to generate ORM code that is more compact and efficient as I would
create if I had to write the code manually.


>>>> If you are interested about more differences in the approaches, you may
>>>> check the Metastorage documentaion:
>>>>
>>>> http://www.metastorage.net/
>>>>
>>> sure, I'll check it out when I have some free time


-- 

Regards,
Manuel Lemos

PHP professionals looking for PHP jobs
http://www.phpclasses.org/professionals/

PHP Classes - Free ready to use OOP components written in PHP
http://www.phpclasses.org/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux