Re: [sqlalchemy] Can't get join() to work

2019-03-29 Thread 'Neil Youngman' via sqlalchemy
On Friday, 29 March 2019 15:10:27 UTC, Neil Youngman wrote: > > > supplying_dealer = relationship(Dealer, supplying_dealer_id == > Dealer.dealer_id) > servicing_dealer = relationship(Dealer, servicing_dealer_id == > Dealer.dealer_id) > > That needs to be: supplying_dealer =

Re: [sqlalchemy] MSSQL String columns often incorrectly encoded as NVARCHAR

2019-03-29 Thread Mike Bayer
OK so I saw that the "N" prefix is not generated with your test case either, so I re-read your email. Can you clarify what you mean by "always encoded as NVARCHAR"? are you referring to the simple fact that a Python string object is passed to the driver, and that the driver is behind the scenes

Re: [sqlalchemy] Documentation options

2019-03-29 Thread Mike Bayer
On Tue, Mar 26, 2019 at 6:28 PM Rich Shepard wrote: > > On Thu, 21 Mar 2019, Mike Bayer wrote: > > > sounds like automap: > > https://docs.sqlalchemy.org/en/latest/orm/extensions/automap.html > > Mike, > > May I send you models.py (off the mail list) to check that I have correctly > applied

Re: [sqlalchemy] Can't get join() to work

2019-03-29 Thread 'Neil Youngman' via sqlalchemy
On Friday, 29 March 2019 15:30:39 UTC, Neil Youngman wrote: > > > That needs to be: > supplying_dealer = relationship(Dealer, > primaryjoin=supplying_dealer_id == Dealer.dealer_id) > servicing_dealer = relationship(Dealer, > primaryjoin=servicing_dealer_id == Dealer.dealer_id) > and

Re: [sqlalchemy] Documentation options

2019-03-29 Thread Rich Shepard
On Fri, 29 Mar 2019, Mike Bayer wrote: I'd prefer any code samples are shared on-list here for the benefit of all to see, thanks. Mike, I was unsure about the proper protocol. I'll post the module here Real Soon Now. Thanks, Rich -- SQLAlchemy - The Python SQL Toolkit and Object

Re: [sqlalchemy] user-defined simple fields in a multi-tenant flask app with ORM

2019-03-29 Thread Jonathan Vanasco
On Friday, March 29, 2019 at 4:39:40 AM UTC-4, Xavier Bustamante Talavera wrote: > > > @Ibrahima and @Jonathan, as I understand you are talking about something > like the Entity–Attribute–Value model > , > adapted to

Re: [sqlalchemy] MSSQL String columns often incorrectly encoded as NVARCHAR

2019-03-29 Thread Mike Bayer
Also note pymssql is not well maintained right now due to lack of funding, please confirm you reproduce your performance concerns using PyODBC with Microsofts ODBC drivers ? That should be considered to be the canonically supported driver right now, works on all platforms very well now. On Fri,

Re: [sqlalchemy] Can't get join() to work

2019-03-29 Thread 'Neil Youngman' via sqlalchemy
On Friday, 29 March 2019 13:48:33 UTC, Simon King wrote: > > > You haven't created a relationship() between Vehicle and Dealer, which > reduces your options a little bit. This should work: > > session.query(Vehicle).join(Dealer, Vehicle.supplying_dealer == > Dealer.id) > > ie. you need

Re: [sqlalchemy] Proper labels in joins when there are multiple relationships with the same table.

2019-03-29 Thread Mike Bayer
On Fri, Mar 29, 2019 at 2:55 PM wrote: > > I have a model, Account, with two foreign keys / relationships to another > model, Users. > > class Account(object): > @declared_attr > def customer_id(cls): > return Column(ForeignKey(User.id)) > @declared_attr > def

Re: [sqlalchemy] Proper labels in joins when there are multiple relationships with the same table.

2019-03-29 Thread ghlstdios
This is definitely along the right track but it conflicts a little bit with the recommended pandas api, for example: query = session.query(Account) return pd.read_sql(query.statement, query.session.bind) I can still follow your method and add each row to a dataframe instead but its not

[sqlalchemy] Proper labels in joins when there are multiple relationships with the same table.

2019-03-29 Thread ghlstdios
I have a model, Account, with two foreign keys / relationships to another model, Users. class Account(object): @declared_attr def customer_id(cls): return Column(ForeignKey(User.id)) @declared_attr def customer(cls): return relationship(User,

Re: [sqlalchemy] Re: Using operators with multiple InstrumentedAttribute instances

2019-03-29 Thread Mike Bayer
I'm not at a computer right now but what you need to do is write a simple recursive descent parser, which makes use of the objects in sqlalchemy.sql.operators for the operators as it parses the string into an expression tree. This is actually a fun classic computer problem I'm sure someone can

Re: [sqlalchemy] Re: Using operators with multiple InstrumentedAttribute instances

2019-03-29 Thread Mike Bayer
On Fri, Mar 29, 2019 at 2:31 PM Ian Miller wrote: > > The code that makes up the query builder I've been working on is pretty > extensive, so I'll go through the high-level basics. > > I've set up a `_base` method that augments the SQLALchemy Base model. Note > the column details retrived in

[sqlalchemy] Re: Using operators with multiple InstrumentedAttribute instances

2019-03-29 Thread Ian Miller
The code that makes up the query builder I've been working on is pretty extensive, so I'll go through the high-level basics. I've set up a `_base` method that augments the SQLALchemy Base model. Note the column details retrived in `get_column_and_json_key_from_sql_name` class method: class

[sqlalchemy] testing/raising errors for queries that do not filter against themselves

2019-03-29 Thread Jonathan Vanasco
I was going batty trying to figure out why a unit test kept passing, while the functionality was clearly broken. I eventually realized the problem was a `filter` that didn't apply to the actual query. The code was essentially this: result = s.query(Foo).filter(Bar.id = 1) but it was

Re: [sqlalchemy] Re: Documentation options

2019-03-29 Thread Rich Shepard
On Sat, 30 Mar 2019, Cameron Simpson wrote: If it is of use I have this shell function: open_dash () { open "dash://$*" } and this alias: alias //=open_dash so that I can go "// search terms here" from the shell command line. Avoids some painful touchpad/mouse mucking around.

Re: [sqlalchemy] Re: Documentation options

2019-03-29 Thread Rich Shepard
On Fri, 29 Mar 2019, Rich Shepard wrote: This looks like the ideal solution. I'll install Dash and use it. Actually, I won't because it's an Apple product for their macOS and iOS. However, slackbuilds.org has a package called Zeal (a simple offline documentation browser inspired by Dash) that

Re: [sqlalchemy] Proper labels in joins when there are multiple relationships with the same table.

2019-03-29 Thread Mike Bayer
On Fri, Mar 29, 2019 at 4:59 PM wrote: > > This is definitely along the right track but it conflicts a little bit with > the recommended pandas api, for example: > query = session.query(Account) > return pd.read_sql(query.statement, query.session.bind) > > I can still follow your method

Re: [sqlalchemy] testing/raising errors for queries that do not filter against themselves

2019-03-29 Thread Mike Bayer
On Fri, Mar 29, 2019 at 4:39 PM Jonathan Vanasco wrote: > > I was going batty trying to figure out why a unit test kept passing, while > the functionality was clearly broken. > > I eventually realized the problem was a `filter` that didn't apply to the > actual query. > > The code was

Re: [sqlalchemy] Can't get join() to work

2019-03-29 Thread Simon King
On Fri, Mar 29, 2019 at 12:17 PM 'Neil Youngman' via sqlalchemy wrote: > > I'm trying to do a select of columns from a join and I simply can't get it to > work. I have tried various different ways to specify the join, with and > without a select_from() and I can't find a combination that works.

Re: [sqlalchemy] MSSQL String columns often incorrectly encoded as NVARCHAR

2019-03-29 Thread Mike Bayer
On Fri, Mar 29, 2019 at 6:20 AM Ian Wagner wrote: > > Hello all, > > I'm trying to get to the bottom of an issue in which Python 3 (unicode by > definition) strings are always encoded as NVARCHAR for at least two backends > (pymssql and pyodbc). Using bytstrings as comparison arguments (for

Re: [sqlalchemy] Re: Documentation options

2019-03-29 Thread Rich Shepard
On Fri, 29 Mar 2019, Xavier Bustamante Talavera wrote: I use Dash to read SQLAlchemy documentation, which is great to search through it and works offline (it downloads the whole docs). Xavier, This looks like the ideal solution. I'll install Dash and use it. Many

Re: [sqlalchemy] user-defined simple fields in a multi-tenant flask app with ORM

2019-03-29 Thread Xavier Bustamante Talavera
Hello everyone and thanks for your answers, >> Simpler solutions would be just using hstore or JSON types, but I would be >> loosing the goodies of SQLAlchemy / Postgres schemas and consistency. > > this is totally how I'd want to do it unless your clients are given > access to program in SQL

[sqlalchemy] Re: Documentation options

2019-03-29 Thread Xavier Bustamante Talavera
Hello Rich, I use Dash to read SQLAlchemy documentation, which is great to search through it and works offline (it downloads the whole docs). Xavier. El dijous, 21 març de 2019 21:20:33 UTC+1, Rich va escriure: > > Are there PDF versions of the docs available for

[sqlalchemy] MSSQL String columns often incorrectly encoded as NVARCHAR

2019-03-29 Thread Ian Wagner
Hello all, I'm trying to get to the bottom of an issue in which Python 3 (unicode by definition) strings are always encoded as NVARCHAR for at least two backends (pymssql and pyodbc). Using bytstrings as comparison arguments (for example Table.column == value.encode('utf-8')) sends a regular

Re: [sqlalchemy] user-defined simple fields in a multi-tenant flask app with ORM

2019-03-29 Thread Ibrahima Gaye
Thanks Xavier, i did not know the pattern had a name :) ( the Entity–Attribute–Value model ,) Ibrahima GAYE Le ven. 29 mars 2019 à 09:39, Xavier Bustamante Talavera a écrit : > Hello everyone and thanks for your

[sqlalchemy] Re: can't update images

2019-03-29 Thread Scheck David
Ok solved it in postgresql thanks -- 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] Can't get join() to work

2019-03-29 Thread 'Neil Youngman' via sqlalchemy
I'm trying to do a select of columns from a join and I simply can't get it to work. I have tried various different ways to specify the join, with and without a select_from() and I can't find a combination that works. the tables look like class Dealer(Base): __tablename__ = 'dealers'