Re: [sqlalchemy] funky session usage to add join conditions and where clauses

2015-09-25 Thread Jonathan Vanasco
fwiw, I struggled with this a while back and then gave up. i ended up writing a few filter__xyz() functions that accept/return a query. in the def, I join needed tables and filter. instead of inspecting the query for tables, I just pass in some flags on how to act. It's not pretty, but it

Re: [sqlalchemy] how to dynamically work with an aliased table?

2015-09-25 Thread Jonathan Vanasco
It looks like I imported the `sqlalchemy.alias` instead of `sqlalchemy.orm.aliased`, and just typod when posting here. switching to sqlalchemy.orm.aliased -- which I used in an identical manner 7 other times in this file -- immediately fixed things. thanks for setting me straight. looks like

Re: [sqlalchemy] funky session usage to add join conditions and where clauses

2015-09-25 Thread Chris Withers
On 25/09/2015 13:58, Mike Bayer wrote: session.query(A).filter(A.id>10).as_at(now)) you'd need to subclass Query and dig into Query.column_descriptions to get at the existing entities, then add all that criterion. remind me where the docs are for plugging in a subclassed Query into a

Re: [sqlalchemy] funky session usage to add join conditions and where clauses

2015-09-25 Thread Chris Withers
On 25/09/2015 16:35, Jonathan Vanasco wrote: fwiw, I struggled with this a while back and then gave up. i ended up writing a few filter__xyz() functions that accept/return a query. in the def, I join needed tables and filter. instead of inspecting the query for tables, I just pass in some

Re: [sqlalchemy] views

2015-09-25 Thread Mike Bayer
On 9/25/15 5:26 AM, Chris Withers wrote: Also forgot to ask... What's support like in Alembic for creating views (especially if the views are described by a declarative class as I'm looking for below...) the trick with views is migrating them when the tables change without lots of

Re: [sqlalchemy] funky session usage to add join conditions and where clauses

2015-09-25 Thread Jonathan Vanasco
It's a code management style that we ended up on :( -- 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 sqlalchemy+unsubscr...@googlegroups.com. To post to this

[sqlalchemy] "No such event 'instrument_class' for target" for mixin that needs to listen to 'instrument_class'

2015-09-25 Thread Chris Withers
Hi All, I have a mixin class here that I've factored out of one project as I want to use it in another one: https://github.com/Mortar/mortar_mixins/blob/master/mortar_mixins/temporal.py The problem is that importing the module seems to result in the following exception being raised: >>>

[sqlalchemy] funk session usage to add join conditions and where clauses

2015-09-25 Thread Chris Withers
Hi All, Suppose I have the following: from sqlalchemyimport Column, Integer, Text, ForeignKey, and_ from sqlalchemy.dialects.postgresqlimport TSRANGEas Range from sqlalchemy.ext.declarativeimport declarative_base Base = declarative_base() class A(Base): id =

Re: [sqlalchemy] how to dynamically work with an aliased table?

2015-09-25 Thread David Allouche
> On 24 Sep 2015, at 17:38, Jonathan Vanasco wrote: > > > > On Thursday, September 24, 2015 at 3:05:56 AM UTC-4, David Allouche wrote: > That looks like the right approach. There is probably something else in your > actual code that is causing "it [to] not work". > >

[sqlalchemy] views

2015-09-25 Thread Chris Withers
Hi All, Is this still the best way to hand views, or are there later and greater things in 1.0+? https://bitbucket.org/zzzeek/sqlalchemy/wiki/UsageRecipes/Views How would I make a view behave like a normal declarative class (column attributes, etc), but while still having it create itself

[sqlalchemy] funky session usage to add join conditions and where clauses

2015-09-25 Thread Chris Withers
Hi All, Suppose I have the following: from sqlalchemy import Column, Integer, Text, ForeignKey, and_from sqlalchemy.dialects.postgresql import TSRANGE as Rangefrom sqlalchemy.ext.declarative import declarative_base Base = declarative_base() class A(Base): id = Column(Integer(),

[sqlalchemy] Storing data on an instance that's deleted when the object is expired

2015-09-25 Thread Adrian
For some methods/properties on a model it might be useful to memoize its result. There are some common decoratos such as cached_property from werkzeug which simply add the value to the object's __dict__ after retrieving it the first time (thus not calling the property's getter again). Or you

Re: [sqlalchemy] loading of relationships

2015-09-25 Thread Julien Cigar
On Thu, Sep 24, 2015 at 11:16:37AM -0400, Mike Bayer wrote: > > > On 9/24/15 9:32 AM, Julien Cigar wrote: > > Hello, > > > > I'm using SQLAlchemy 1.0.8 with joinedload inheritance. On one of the > > Child I have a relationship property and I wondered if there is an easy > > way to innerjoin=True

Re: [sqlalchemy] how to dynamically work with an aliased table?

2015-09-25 Thread Mike Bayer
On 9/25/15 2:41 AM, David Allouche wrote: On 24 Sep 2015, at 17:38, Jonathan Vanasco > wrote: On Thursday, September 24, 2015 at 3:05:56 AM UTC-4, David Allouche wrote: That looks like the right approach. There is probably

Re: [sqlalchemy] Storing data on an instance that's deleted when the object is expired

2015-09-25 Thread Mike Bayer
On 9/25/15 8:22 AM, Adrian wrote: For some methods/properties on a model it might be useful to memoize its result. There are some common decoratos such as cached_property from werkzeug which simply add the value to the object's __dict__ after retrieving it the first time (thus not calling

Re: [sqlalchemy] views

2015-09-25 Thread Mike Bayer
On 9/25/15 3:13 AM, Chris Withers wrote: Hi All, Is this still the best way to hand views, or are there later and greater things in 1.0+? https://bitbucket.org/zzzeek/sqlalchemy/wiki/UsageRecipes/Views How would I make a view behave like a normal declarative class (column attributes,

Re: [sqlalchemy] views

2015-09-25 Thread Chris Withers
Also forgot to ask... What's support like in Alembic for creating views (especially if the views are described by a declarative class as I'm looking for below...) > On 25 Sep 2015, at 08:13, Chris Withers wrote: > > Hi All, > > Is this still the best way to hand