Trac-like Query Builder

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Trac-like Query Builder

Randy Syring
Does anyone know of a Python package that would provide query building
functionality like Trac has when doing a custom query on the tickets?

--
--------------------------------------
Randy Syring
RCS Computers & Web Solutions
502-644-4776
http://www.rcs-comp.com

"Whether, then, you eat or drink or
whatever you do, do all to the glory
of God." 1 Cor 10:31

_______________________________________________
Web-SIG mailing list
[hidden email]
Web SIG: http://www.python.org/sigs/web-sig
Unsubscribe: http://mail.python.org/mailman/options/web-sig/lists%40nabble.com
Reply | Threaded
Open this post in threaded view
|

Re: Trac-like Query Builder

Gustavo Narea
Hello,

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

With it, you'll be able to have text-based filters like:
 * ticket.id == 12
 * ticket.assignee == users.myself or not ticket.assignee
 * ticket.assignee in {users.myself, users.admin}
 * ticket.title contains "Foo Bar"

Or, without namespaces:
 * id == 12
 * assignee == myself or not assignee
 * assignee in {myself, admin}
 * title contains "Foo Bar"

Unfortunately it's a rather new piece of software and should get the first
alpha/usable release this week.

HTH,
--
Gustavo Narea <xri://=Gustavo>.
| Tech blog: =Gustavo/(+blog)/tech  ~  About me: =Gustavo/about |
_______________________________________________
Web-SIG mailing list
[hidden email]
Web SIG: http://www.python.org/sigs/web-sig
Unsubscribe: http://mail.python.org/mailman/options/web-sig/lists%40nabble.com
Reply | Threaded
Open this post in threaded view
|

Re: Trac-like Query Builder

Robert Brewer-4
RE: [Web-SIG] Trac-like Query Builder

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
[hidden email]

[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


_______________________________________________
Web-SIG mailing list
[hidden email]
Web SIG: http://www.python.org/sigs/web-sig
Unsubscribe: http://mail.python.org/mailman/options/web-sig/lists%40nabble.com
Reply | Threaded
Open this post in threaded view
|

Re: Trac-like Query Builder

Gustavo Narea
Hello,

Booleano and Geniusql seem to be two different things:
 * If you need to *parse* a text-based filter (aka "boolean expression"), use
Booleano.
 * If you already have the data in a useful form (i.e., no need to parse
anything), use Geniusql.

BTW, you can use a Booleano parse tree not only to create an SQL `WHERE`
clause, but also to create a SQLAlchemy filter, for example -- you can turn
these trees into anything you need (or at least that's the goal).

Cheers,

  - Gustavo.


Robert said:
>  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
>  [hidden email]
>
>  [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
--
Gustavo Narea <xri://=Gustavo>.
| Tech blog: =Gustavo/(+blog)/tech  ~  About me: =Gustavo/about |
_______________________________________________
Web-SIG mailing list
[hidden email]
Web SIG: http://www.python.org/sigs/web-sig
Unsubscribe: http://mail.python.org/mailman/options/web-sig/lists%40nabble.com