Building queries on the fly

Robert Gravina <[email protected]> Mon, 18 Sep 2006 03:57:40 +0900
Newsgroups gmane.comp.python.quotient.dev
Message-ID <[email protected]>
Hi all and thanks again for your help with Axiom! I'm very happy with  
it - it's object oriented enough to make persisting objects easy  
while still having a relational DB underneath (no pickling and data  
that's easy to get at in case you get in a, wait for it, pickle!).  
Thanks, I'll be here all week. Try the veal.

Anyhow, I'd really like to build up AND query criteria  
programatically. My Twisted clients will submit search criteria (e.g.  
name starts with "A", description does not contain "foo" etc.) and  
then I'd like to build up an AND query based on these, and return the  
results. So for example, if the client sends something like this,  
which basically says "give me all Items with the name "foo" who's  
"owner" attribute (a reference to another Item) has an attribute  
"likes" which does not equal "icecream":

{"MyItem.name":["operator":"equals", "value":"foo"],
"MyItem.owner.likes":["operator":"not equals", "value":"icecream"]}

Then I could turn this into

self.store.query(MyItem, AND(MyItem.name == "foo",
							MyItem.owner == MyOwnerItem.storeID,
							MyOwnerItem.likes != "icecream"))

The main part I can't figure out is how to call AND with many  
criteria programatically. How I turn my criteria list in to an Axiom  
friendly set of criteria is not really something I want to bother you  
all with, but I thought I'd include my ideas so you understand what I  
am trying to achieve.

Thanks again for your help,

Robert