[storm] Store.find() and GROUP BY ORDER BY
Vsevolod Balashov
vsevolod at balashov.name
Wed Sep 12 05:25:19 BST 2007
Hello!
Using Storm, I found a nasty drawback:
With Store.find() can I get a list of objects using different conditions WHERE.
I can even use the OFFSET and LIMIT through
Store.find(...).config(offset, limit)
that can be useful in web-applications. IMHO this design with "config" is uglu.
But I have no way I can get a list of objects using the GROUP BY and
ORDER BY expressions. Only tuple of unicode strings using
Store.execute(Select(...)).
I think that is absolutely bad and developed the following function "select".
She repeats almost Store.find code and I hope that in futire version
of Storm GROUP BY, ORDER BY, OFFSET, LIMIT, DISTINCT and other
expressions can be put directly into Store.find.
from storm import Undef
from storm.info import get_cls_info
from storm.expr import Select
def select(store, cls_spec, where=Undef, \
order_by=Undef, group_by=Undef, limit=Undef, offset=Undef, distinct=False):
store.flush()
if type(cls_spec) is tuple:
cls_spec_info = tuple(get_cls_info(cls) for cls in cls_spec)
# XXX cls_spec_info.columns is tuple of tuple ?
else:
cls_spec_info = get_cls_info(cls_spec)
sel = Select([cls_spec_info.columns], where = where,\
order_by=order_by, group_by=group_by, limit=limit,
offset=offset, distinct=distinct)
return store._result_set_factory(store, cls_spec_info, where, select = sel)
--
Vsevolod Balashov
http://vsevolod.balashov.name
More information about the storm
mailing list