Re: [sqlalchemy] Re: Is it good practice to copy all sqlalchemy models (tables) for every API I create?

2019-05-13 Thread Desmond Lim
Thanks Jonathan. Exactly what I wanted to know. Desmond On Tue, 14 May 2019 at 02:22, Jonathan Vanasco wrote: > Are all of these APIs for the same company/organization (e.g. in-house > services), or are you developing something for different companies (you are > an agency with clients)? > > If

[sqlalchemy] Conditional onupdate

2019-05-13 Thread Tony Cao
Hi all, Is there way to use Column.onupdate conditionally? For example, say I have: class A(Base): foo = Column(String) bar = Column(String) foo_updated = Column(DateTime, onupdate=update_fn) # Should only update when foo is updated def update_fn(context): if ...: # How can I ch

[sqlalchemy] Re: Is it good practice to copy all sqlalchemy models (tables) for every API I create?

2019-05-13 Thread Jonathan Vanasco
Are all of these APIs for the same company/organization (e.g. in-house services), or are you developing something for different companies (you are an agency with clients)? If everything is for the same company, I typically define and maintain a single model in a dedicated separate package. The

Re: [sqlalchemy] Re: Query last relation created and attributes

2019-05-13 Thread Mike Bayer
On Mon, May 13, 2019 at 10:37 AM Scheck David wrote: > the problem is that I can't use SQL for this because this is a mixins that > I use for several objects (tables) because they all have this status > structure... yes it's quite difficult to do : > I don't know what it is you want to do so if

Re: [sqlalchemy] Re: Query last relation created and attributes

2019-05-13 Thread James Fennell
I think Mike's suggestion was to construct the raw SQL string you want, then reverse engineer to get the correct SQL Alchemy code, which you can then use with your different models. For complicated SQL logic I think this is a good practice in general. You current question seems like a general SQL

Re: [sqlalchemy] Re: Query last relation created and attributes

2019-05-13 Thread Scheck David
the problem is that I can't use SQL for this because this is a mixins that I use for several objects (tables) because they all have this status structure... yes it's quite difficult to do : right now I'm on this stage, but still don't work self.session.query(Object).outerjoin(ObjectStatus).outerjo

Re: [sqlalchemy] Re: Query last relation created and attributes

2019-05-13 Thread Mike Bayer
Hi - I was hoping someone could jump in on this. do you know the SQL that you want to emit? E.g. plain SQL string. I can help you do that part. On Mon, May 13, 2019 at 9:11 AM Scheck David wrote: > > I think I'm near but I can't finish : > > for all the structure : https://dpaste.de/fek5#L

[sqlalchemy] Re: Query last relation created and attributes

2019-05-13 Thread Scheck David
I think I'm near but I can't finish : for all the structure : https://dpaste.de/fek5#L and here my query : self.session.query(Object).outerjoin(ObjectStatus).outerjoin(Status)\ .group_by(Object).with_entities(Object, func.max(Status.datum).label("status_datum")).subquery() self.s