[sqlalchemy] recipe advice for special 1:1 relationships

2019-04-04 Thread Kent
I've used sqlalchemy for many years and something that has come up now and then is the need for adding a relationship to a mapper that normally would be a collection (uselist=True) but instead we want to target a specific record in that collection. As a simplified illustration, suppose you

Re: [sqlalchemy] recipe advice for special 1:1 relationships

2019-04-04 Thread Mike Bayer
On Thu, Apr 4, 2019 at 9:34 AM Kent wrote: > > I've used sqlalchemy for many years and something that has come up now and > then is the need for adding a relationship to a mapper that normally would be > a collection (uselist=True) but instead we want to target a specific record > in that

Re: [sqlalchemy] Re: recipe advice for special 1:1 relationships

2019-04-04 Thread Mike Bayer
DELETEs are always by primary key, and you'll want to set up the cascade="all,delete-orphan" and youll need single_parent=True also. On Thu, Apr 4, 2019 at 11:55 AM Kent wrote: > > Will > > a.b1 = None > > > issue a delete statement that also contains the WHERE clause to make that > safe? (Or,

[sqlalchemy] Re: recipe advice for special 1:1 relationships

2019-04-04 Thread Kent
Excellent, thanks very much! -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper http://www.sqlalchemy.org/ To post example code, please provide an MCVE: Minimal, Complete, and Verifiable Example. See http://stackoverflow.com/help/mcve for a full description. --- You

[sqlalchemy] Re: recipe advice for special 1:1 relationships

2019-04-04 Thread Kent
Will a.b1 = None issue a delete statement that also contains the WHERE clause to make that safe? (Or, is the delete always by primary key anyway?) -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper http://www.sqlalchemy.org/ To post example code, please provide an MCVE:

Re: [sqlalchemy] Support for backup node connection.

2019-04-04 Thread rishi reddy
Unfortunately, I am using Superset which uses SQLALCHEMY for metadata DB connection. So I am not sure if I could have control over the code or not. Is there any other way I could do this? On Thursday, 4 April 2019 15:24:42 UTC-4, Mike Bayer wrote: > > the issue describing how this feature can

[sqlalchemy] Support for backup node connection.

2019-04-04 Thread rishi reddy
Hi All, I have Postgres DB two node cluster and using SQLALCHEMY_DATABASE_URI were we can give only one node details. But how can i achieve a scenario were if the given node goes down SQLALCHEMY will connect to the other backup node. Is there an option of giving the backup node details in

Re: [sqlalchemy] Support for backup node connection.

2019-04-04 Thread Mike Bayer
the issue describing how this feature can be added is at: https://github.com/sqlalchemy/sqlalchemy/issues/4392 for now you need to use creator to connect to psycopg2 directly and return the connection yourself from a function, which you pass to create_engine:

Re: [sqlalchemy] Support for backup node connection.

2019-04-04 Thread Mike Bayer
On Thu, Apr 4, 2019 at 3:49 PM rishi reddy wrote: > > Unfortunately, I am using Superset which uses SQLALCHEMY for metadata DB > connection. So I am not sure if I could have control over the code or not. Is > there any other way I could do this? unfortunately no until someone has time to help