[sqlalchemy] alternate way to filter queries

2013-08-26 Thread lars van gemerden
Hi all, This might be a bit of a stretch but here it goes: Say that i have a lambda function that takes a mapped object and teturns whether it is valid; e.g: lambda person: person.age 17 or person.length 1.75 is it possible to use this method to perform an sqla query on the database?

Re: [sqlalchemy] alternate way to filter queries

2013-08-26 Thread Michael Bayer
On Aug 26, 2013, at 11:14 AM, lars van gemerden l...@rational-it.com wrote: Hi all, This might be a bit of a stretch but here it goes: Say that i have a lambda function that takes a mapped object and teturns whether it is valid; e.g: lambda person: person.age 17 or person.length

Re: [sqlalchemy] testing for an association proxy (possible bug and patch included)

2013-08-26 Thread Michael Bayer
On Aug 23, 2013, at 6:34 PM, jason kirtland j...@discorporate.us wrote: The patch seems like surprising Python behavior to me. Traversing across a None is almost certainly a bug in regular code, and quashing that error by default feels dangerous. I would want this to raise by default (and

Re: [sqlalchemy] alternate way to filter queries

2013-08-26 Thread lars van gemerden
Hi Michael, So just to be sure, if i understand correctly and i have: func = lambda person: person.age 17 or person.length 1.75 I can do: class Person(Base): # @hybrid_method def run_filter(self, fn): return fn(self)

Re: [sqlalchemy] alternate way to filter queries

2013-08-26 Thread Simon King
On 26 Aug 2013, at 19:15, lars van gemerden l...@rational-it.com wrote: On Monday, August 26, 2013 5:23:07 PM UTC+2, Michael Bayer wrote: On Aug 26, 2013, at 11:14 AM, lars van gemerden la...@rational-it.com wrote: Hi all, This might be a bit of a stretch but here it goes: Say that

Re: [sqlalchemy] alternate way to filter queries

2013-08-26 Thread Michael Bayer
oh , the or won't work as a hybrid, you either need to use the binary op | or otherwise run through some filter that will give you expression vs. local behavior. On Aug 26, 2013, at 2:15 PM, lars van gemerden l...@rational-it.com wrote: Hi Michael, So just to be sure, if i understand

Re: [sqlalchemy] alternate way to filter queries

2013-08-26 Thread lars van gemerden
Hmm, too bad. I do have the lambda methods in string form so i'll probably have to write a parser and construct the query with unions and intersects (or filter(A.b 1, A.c0) like calls instead of intersects). No how did writing a parser tree go |-)? CL On Monday, August 26, 2013 8:27:16 PM

[sqlalchemy] How to create a one-to-many relationship with a default one-to-one property for I18N

2013-08-26 Thread Florian Rüchel
Hey there, I have already posted this on stackoverflowhttp://stackoverflow.com/questions/18304212/how-do-i-create-a-one-to-many-relationship-with-a-default-one-to-one-property-fobut not recieved an answer yet so I thought I might try here. To quote from my original question: Suppose we have

Re: [sqlalchemy] How to define metaclass for a class that extends from sqlalchemy declarative base ?

2013-08-26 Thread Praveen
The problem with using Mixins is that you need to know the definition of columns already for creating the mixin class. What I am trying to do is more like get the definition dynamically on the fly.Take a look at this: def get_properties(tablename, map): table_inspector =

Re: [sqlalchemy] How to define metaclass for a class that extends from sqlalchemy declarative base ?

2013-08-26 Thread Praveen
Sorry, it should've been: class Enum_Sample(Base): Typo. On Mon, Aug 26, 2013 at 4:35 PM, Praveen praveen.venk...@gmail.com wrote: The problem with using Mixins is that you need to know the definition of columns already for creating the mixin class. What I am trying to do is more like get

Re: [sqlalchemy] How to define metaclass for a class that extends from sqlalchemy declarative base ?

2013-08-26 Thread Michael Bayer
On Aug 26, 2013, at 4:35 PM, Praveen praveen.venk...@gmail.com wrote: The problem with using Mixins is that you need to know the definition of columns already for creating the mixin class. What I am trying to do is more like get the definition dynamically on the fly.Take a look at this:

Re: [sqlalchemy] How to define metaclass for a class that extends from sqlalchemy declarative base ?

2013-08-26 Thread Michael Bayer
On Aug 26, 2013, at 5:16 PM, Michael Bayer mike...@zzzcomputing.com wrote: On Aug 26, 2013, at 4:35 PM, Praveen praveen.venk...@gmail.com wrote: The problem with using Mixins is that you need to know the definition of columns already for creating the mixin class. What I am trying to do

Re: [sqlalchemy] How to define metaclass for a class that extends from sqlalchemy declarative base ?

2013-08-26 Thread Michael Bayer
OK here we are, had to switch approaches due to a bug with the column reflect event, to use the aforementioned __mapper_cls__ (had the name wrong), so I think you'll see this is a pretty open-ended way to control how something maps as you're given total access to mapper() here: from sqlalchemy

Re: [sqlalchemy] How to define metaclass for a class that extends from sqlalchemy declarative base ?

2013-08-26 Thread Praveen
Does this work in sqlalchemy 0.6.1 ? On Mon, Aug 26, 2013 at 5:36 PM, Michael Bayer mike...@zzzcomputing.comwrote: OK here we are, had to switch approaches due to a bug with the column reflect event, to use the aforementioned __mapper_cls__ (had the name wrong), so I think you'll see this is

Re: [sqlalchemy] How to define metaclass for a class that extends from sqlalchemy declarative base ?

2013-08-26 Thread Praveen
I am getting ImportError for the following: from sqlalchemy.ext.declarative import DeferredReflection from sqlalchemy import event I use sqlalchemy 0.6.1. Is there any way I can make it work in 0.6.1 ? On Mon, Aug 26, 2013 at 5:38 PM, Praveen praveen.venk...@gmail.com wrote: Does this work

Re: [sqlalchemy] How to define metaclass for a class that extends from sqlalchemy declarative base ?

2013-08-26 Thread Michael Bayer
you'd need to hand-roll the deferred reflection part, there's an example in 0.7 called declarative_reflection but it might require features that aren't in 0.6. I'd not be looking to add any kind of slick/magic systems to an 0.6 app, 0.6 is very early in the curve for declarative techniques.

Re: [sqlalchemy] How to define metaclass for a class that extends from sqlalchemy declarative base ?

2013-08-26 Thread Praveen
Could you please point me to the link where I can find the example ? On Mon, Aug 26, 2013 at 5:41 PM, Michael Bayer mike...@zzzcomputing.comwrote: you'd need to hand-roll the deferred reflection part, there's an example in 0.7 called declarative_reflection but it might require features that

Re: [sqlalchemy] How to define metaclass for a class that extends from sqlalchemy declarative base ?

2013-08-26 Thread Praveen
nvm... i found it. On Mon, Aug 26, 2013 at 5:46 PM, Praveen praveen.venk...@gmail.com wrote: Could you please point me to the link where I can find the example ? On Mon, Aug 26, 2013 at 5:41 PM, Michael Bayer mike...@zzzcomputing.comwrote: you'd need to hand-roll the deferred reflection

Re: [sqlalchemy] How to create a one-to-many relationship with a default one-to-one property for I18N

2013-08-26 Thread Michael Bayer
On Aug 26, 2013, at 3:43 PM, Florian Rüchel florian.ruec...@gmail.com wrote: Hey there, I have already posted this on stackoverflow but not recieved an answer yet so I thought I might try here. To quote from my original question: I've seen it, and the issue is that the question is

Re: [sqlalchemy] How to define metaclass for a class that extends from sqlalchemy declarative base ?

2013-08-26 Thread Praveen
I tried your example in sqlalchemy 0.6 by manually plugging in api.py library (attached) that I got from herehttps://bitbucket.org/miracle2k/sqlalchemy/src/2d28ed97d3221a133b4b297a229deb294088affe/lib/sqlalchemy/ext/declarative/api.py?at=default . I get this error: File path\to\sample_orm.py,