[Web-SIG] Trac-like Query Builder

Robert Brewer fumanchu at aminus.org
Tue Jun 30 17:16:47 CEST 2009


Gustavo Narea wrote:
> Randy said:
> > Does anyone know of a Python package that would provide query building
> > functionality like Trac has when doing a custom query on the tickets?
> 
> Are you talking about a front-end that allows end-users "assemble" the
> query, or a back-end that turns user-provided data into a result filter
> (e.g., SQL `WHERE` clause)?
> 
> If it's the later, you may want to see this:
> https://launchpad.net/booleano
> Unfortunately it's a rather new piece of software and should get the first
> alpha/usable release this week.

Heck, if all you want is the back end, Geniusql (and therefore Dejavu) allows you to build comparison expressions and combine them with "+", "&", and "|":

>>> from geniusql import logic
>>> a = logic.comparison('Name', 6, ['Dave', 'Jerry', 'Sue'])
>>> a
logic.Expression(lambda x: x.Name in ['Dave', 'Jerry', 'Sue'])
>>> b = logic.comparison('Size', 2, 30)
>>> b
logic.Expression(lambda x: x.Size == 30)

>>> a + b
logic.Expression(lambda x: (x.Name in ['Dave', 'Jerry', 'Sue']) and (x.Size == 30))
>>> a & b
logic.Expression(lambda x: (x.Name in ['Dave', 'Jerry', 'Sue']) and (x.Size == 30))
>>> a | b
logic.Expression(lambda x: (x.Name in ['Dave', 'Jerry', 'Sue']) or (x.Size == 30))

>>> c = logic.Expression(lambda g, h: g.Name == h.Name)
>>> c
logic.Expression(lambda g, h: g.Name == h.Name)
>>> a + c
logic.Expression(lambda x, h: (x.Name in ['Dave', 'Jerry', 'Sue']) and (x.Name == h.Name))

You then pass those to the storage layer where they are automatically converted to backend-specific SQL etc. Been runnin' like a champ for years, not days. [1]


Robert Brewer
fumanchu at aminus.org

[1]  OK, I did have to commit a patch just now for comparison() in py2.5+--but it's a short one ;)
http://www.aminus.net/geniusql/changeset/280
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/web-sig/attachments/20090630/41ee4b91/attachment.htm>


More information about the Web-SIG mailing list