Storm vs. SQLAlchemy
James Henstridge
james at jamesh.id.au
Wed Jul 11 07:38:15 BST 2007
On 11/07/07, Lucas Huerta <huerta.lucas at gmail.com> wrote:
> Hello Gustavo,
>
> One of the things that makes an ORM like SQLObject handy is the fact that it
> can generate the schema in a database agnostic manner. Since Storm doesn't
> handle schema management, could I conclude that vendor specific ddl must be
> handled manually?
>
> Furthermore, I noticed an example in the Storm tutorial which appeared to
> use raw SQL:
>
> >>> ruy.name = SQL("(SELECT name || ' Ritcher' FROM person WHERE id=4)")
>
> Is it possible with Storm, to generate SQL queries programatically, and in a
> database agnostic
> manner?
If you are asking if Storm has an equivalent of SQLObject's
sqlbuilder, then the answer is yes. The storm.expr module includes
most of the functions you would be looking for, and the table field
properties on classes can be used in those expressions:
from storm.expr import And
result_set = store.find(
(Table1, Table2), And(Table1.foreign_key == Table2.id,
Table2.somefield == 42))
for (t1, t2) in result_set:
# do something with the pairs
While the underlying implementation is quite different, the result is
quite similar to what you'd get with SQLObject's sqlbuilder
expressions.
The SQL() function used in the tutorial is roughly equivalent to
SQLObject's SQLConstant() builder expression.
James.
More information about the storm
mailing list