Re: [sqlalchemy] turning only loaded columns into a dict

2018-05-02 Thread Jonathan Vanasco
On Wednesday, May 2, 2018 at 5:53:56 PM UTC-4, Mike Bayer wrote: > > if you only care about things that are loaded, like before, look in > inspect(instance).dict , that's what's loaded > Thanks. I'll migrate my proof-of-concept to use `inspect`. -- SQLAlchemy - The Python SQL Toolkit and O

Re: [sqlalchemy] turning only loaded columns into a dict

2018-05-02 Thread Mike Bayer
if you only care about things that are loaded, like before, look in inspect(instance).dict , that's what's loaded On Wed, May 2, 2018 at 4:24 PM, Jonathan Vanasco wrote: > I have a mixin that helps convert object to JSON using a `columns_as_dict` > method. > > it looks like this: > > from sqlalc

Re: [sqlalchemy] Is it possible to call a stored procedure that takes a table-valued parameter with SQLAlchemy?

2018-05-02 Thread Mike Bayer
On Wed, May 2, 2018 at 4:12 PM, Cameron Hassler wrote: > I'm trying to execute a stored procedure on MSSQL Server that takes a > single, table-valued parameter. The parameter itself is of a custom type > "StringTable" defined like so: > > CREATE TYPE [dbo].[StringTable] AS TABLE([strValue] [nvarch

Re: [sqlalchemy] Is FLOAT(53) the best way to guarantee a double-precision generic column type

2018-05-02 Thread Mike Bayer
FLOAT types will have floating point inaccuracy. I have no idea if 53 is actually supported, usually floating point accuracy starts to hit various limits at something like 10 digits. Usually the NUMERIC type is the best bet since it uses Python Decimal objects. You should work up some tests t

Re: [sqlalchemy] How to override append and remove methods used in orm.relationships

2018-05-02 Thread Mike Bayer
On Wed, May 2, 2018 at 12:22 PM, Diego Quintana wrote: > Hello, thanks again for your help. I'm not sure I understand what you said > totally, and I believe this is the most simple MCVE I can provide. > > My local tests use postgresql, but I'm setting an in-memory sqlite3 engine > here. I'm not fo

[sqlalchemy] turning only loaded columns into a dict

2018-05-02 Thread Jonathan Vanasco
I have a mixin that helps convert object to JSON using a `columns_as_dict` method. it looks like this: from sqlalchemy.orm import class_mapper as sa_class_mapper class Mixin(object): def columns_as_dict(self): _cls = self.__class__ return dict((col.name, getattr(self, col.na

[sqlalchemy] Is it possible to call a stored procedure that takes a table-valued parameter with SQLAlchemy?

2018-05-02 Thread Cameron Hassler
I'm trying to execute a stored procedure on MSSQL Server that takes a single, table-valued parameter. The parameter itself is of a custom type "StringTable" defined like so: CREATE TYPE [dbo].[StringTable] AS TABLE([strValue] [nvarchar](max) NULL) Is it possible to execute this procedure using

[sqlalchemy] Is FLOAT(53) the best way to guarantee a double-precision generic column type

2018-05-02 Thread Van Klaveren, Brian N.
I'm trying to work on a universal table generator based on in-memory table objects. The code is based on the work from the pandas to_sql. I'll be targeting Oracle, Postgres, MySQL, and SQLite for sure. It seems like making sure to use Float(53) is the best way to guarantee that a column will be

Re: [sqlalchemy] How to override append and remove methods used in orm.relationships

2018-05-02 Thread Diego Quintana
Hello, thanks again for your help. I'm not sure I understand what you said totally, and I believe this is the most simple MCVE I can provide. My local tests use postgresql, but I'm setting an in-memory sqlite3 engine here. I'm not fond of the differences between two backends, but the tests run

Re: [sqlalchemy] How to override append and remove methods used in orm.relationships

2018-05-02 Thread Mike Bayer
On Wed, May 2, 2018 at 10:14 AM, Diego Quintana wrote: > This worked. > > I'm trying to achieve some rather tricky behaviour, where > > Adding a children to some parent will also add the child's pets to the > parent > Removing a children from some parent will also remove every current > relationsh

Re: [sqlalchemy] How to override append and remove methods used in orm.relationships

2018-05-02 Thread Diego Quintana
This worked. I'm trying to achieve some rather tricky behaviour, where 1. Adding a children to some parent will also add the child's pets to the parent 2. Removing a children from some parent will also remove every current relationship that the Parent has with such pet 3. If up

Re: [sqlalchemy] best ways to preserve and analyze detached/unbound items

2018-05-02 Thread Mike Bayer
yes, persistent_to_detached: http://docs.sqlalchemy.org/en/latest/orm/session_events.html#persistent-to-detached On Tue, May 1, 2018 at 11:18 PM, Jonathan Vanasco wrote: > Thanks for all this help, Mike! > > On Tuesday, May 1, 2018 at 8:56:35 PM UTC-4, Mike Bayer wrote: >> >> at what "moment in t