Sorting
Gustavo Niemeyer
gustavo at niemeyer.net
Tue Jul 17 15:20:02 BST 2007
Hello again!
> How should one execute "group by" or "order by" in the Storm ORM way?
GROUP BY is already designed, but isn't yet implemented. It will
probably be the next feature implemented. Here's how it will work:
foo, count = store.find((Foo, Count(Foo.name))).group_by(Foo.name)
I've added another section to the tutorial about ordering and
limiting of results. Here it is:
==== Ordering and limiting results ====
Ordering and limiting results obtained are certainly among the
simplest and yet most wanted features for such tools, so we want
to make them very easy to understand and use, of course.
A code of line is worth a thousand words, so here are a few examples
that demonstrate how it works:
>>> garry = store.add(Employee(u"Garry Glare"))
>>> result = store.find(Employee)
>>> [employee.name for employee in result.order_by(Employee.name)]
[u'Ben Bill', u'Garry Glare', u'Mike Mayer']
>>> [employee.name for employee in result.order_by(Desc(Employee.name))]
[u'Mike Mayer', u'Garry Glare', u'Ben Bill']
>>> [employee.name for employee in result.order_by(Employee.name)[:2]]
[u'Ben Bill', u'Garry Glare']
--
Gustavo Niemeyer
http://niemeyer.net
More information about the storm
mailing list