On 12/30/2015 06:50 AM, Chris Withers wrote:
> Mike,
>
> Would you be interested in a pull request to add a Query and/or Session
> option for this?
sadly no, as I don't want to complicate the API with many use cases /
internals. The Core select() object already made this mistake (it in
fact has "append_whereclause()" and other self-mutating methods, all
doubling upon the generative ones and making the implementation more
complex than it needs to be), I'd love if select() didn't have its
current three different ways to specify a WHERE clause.
>
> My use case right now is putting the query in a registry so other
> callables down the line can refine the search criteria, but I may well
> not being alone in thinking that:
>
> query = self.session.query(Club)
> query.filter(Club.name.ilike(club))
> query.order_by('name')
> possible = query.all()
>
> ...is easier to read than:
>
> possible = self.session.query(Club)\
> .filter(Club.name.ilike(club))\
> .order_by('name')\
> .all()
I actually find the latter easier to read, but you might as well use the
BakedQuery as it does only do in-place mutation, plus will cache the
generated SQL once invoked.
as far as the registry use case, pass-by-value is easy enough, just
stick your Query inside of a dictionary or other object and that's
what's passed.
>
> cheers,
>
> Chris
>
> On 28/12/2015 15:22, Mike Bayer wrote:
>> not through the current API, no. you'd need to write some modifier to
>> the @generative decorator and basically tinker with things to make it do
>> that.
>>
>>
>>
>> On 12/28/2015 06:18 AM, Chris Withers wrote:
>>> Hi All,
>>>
>>> Is there anything I can do to make Query instance non-generative?
>>>
>>> query = session.query(Foo)
>>> query.filter(Foo.x==1)
>>>
>>> ...and have the query actually be modified rather than returning a new
>>> query with the clause added?
>>>
>>> cheers,
>>>
>>> Chris
>>>
>
> --
> You received this message because you are subscribed to the Google
> Groups "sqlalchemy" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to [email protected]
> <mailto:[email protected]>.
> To post to this group, send email to [email protected]
> <mailto:[email protected]>.
> Visit this group at https://groups.google.com/group/sqlalchemy.
> For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.