3 messages in com.googlegroups.sqlalchemy[sqlalchemy] Re: Generative query met...
FromSent OnAttachments
Gaetan de Menten24 Apr 2007 02:41.diff
Michael Bayer24 Apr 2007 05:49 
Gaetan de Menten25 Apr 2007 02:22 
Subject:[sqlalchemy] Re: Generative query methods for aggregates.
From:Gaetan de Menten (gdem@gmail.com)
Date:04/25/2007 02:22:40 AM
List:com.googlegroups.sqlalchemy

On 4/24/07, Michael Bayer <mike@zzzcomputing.com> wrote:

On Apr 24, 2007, at 5:42 AM, Gaetan de Menten wrote:

Here is an experimental patch to add generative aggregate methods on query objects.

My use case is that I have a class which is often queried with a sum query, from different places. But those different places usually add a filter on top of that basic query. And since I don't like repeating myself, I wanted a way to factor the common part.

Here is some (untested) example:

score_query = Query(Tag).sum_clause(tags_table.c.score1 * tags_table.c.score2) fun_score_query = score_query.filter_by(name='fun')

[... on another place ...]

user_fun_score = fun_score_query.filter_by(user=self).scalar()

if we can use a verb in the name, like "apply_sum()", sure.

I created ticket 552 for this with an improved patch.

http://www.sqlalchemy.org/trac/ticket/552