[storm] Query questions and misc. comments
Håvard Gulldahl
havard at gulldahl.no
Tue Dec 11 20:46:52 GMT 2007
[Re-sending the reply that I by accident sent to Morten privately]
Hi Morten,
I feel your frustration. I've only just started using storm myself.
While the tutorial is great for learning the tutorial, all the other
stuff is a bit more veiled. In my experience, the best way to explore
storm is
1) study the source files (obviously ;)
2) turn on debugging, since you'll see the sql query that storm
expands from your code:
import storm.database
storm.database.DEBUG = True
On 12/9/07, Morten Siebuhr <msiebuhr at sbhr.dk> wrote:
> 1. It is in no way obvious from the tutorial or manual-page how one
> does stuff like NOT, LIKE, IN, AND and OR in Storm. I've seen
It's not obvious at first. After a while it's just easy as pie. Check
it (code semi-tested):
LIKE:
store.find(klass, klass.col.like('%skabelone'))
NOT:
from storm.expr import Not
store.find(klass, Not(klass.col < 10))
IN:
from storm.expr import In
store.find(klass, In(klass.id, [1,2,3,10,11,12]))
AND/OR:
from storm.expr import And, Or
expr1 = And(klass.col == 2, klass.disabled == False)
store.find(klass, Or(klass.sticky, expr1))
So, since this is all serializable, you can easily build up a python
list of expressions, and then, And() or Or() it together, depending on
your application:
expressions = []
#... loop through input and build atomic expressions, e.g. ...
# expressions += [ stormer.lastname.like('%buhr') ]
# expressions += [ stormer.gender == 'Male' ]
# and then:
store.find(stormer, And(*expressions))
> 2. From reading the generated documentation - it seems sub-queries
> are possible, but I can't really figure out how.
SELECT:
from storm.expr import Select, In
expr1 = Select(klass2, klass2.enabled == True)
store.find(klass, In(klass.foreignId, expr1))
> 3. How - if at all - does Storm handle VIEWs? I'd really like to
> hide away some of the complex queries, but I'd prefer not to
> give up using Storm-objects.
I don't know anything about this.
Hope this helps,
Håvard
--
Håvard Gulldahl <havard at gulldahl.no>
More information about the storm
mailing list