Re: [sqlalchemy] How to infer the ORM model class from an update()/insert() object?

2022-03-28 Thread mkmo...@gmail.com
Hi Mike, Thanks for taking a look into it. Even if only the simple case can be taken care of in 2.0, that would be good as it would set up 2.x for completing the edge cases over time. > select(User).from_statement(insert(User).returning(User, User.my_column_property)) In my particular case,

Re: [sqlalchemy] How to infer the ORM model class from an update()/insert() object?

2022-03-28 Thread Mike Bayer
since it will be very hard to change this after 2.0 is released I will try to further attempt to get ORM objects to be returned, though this will not at first support any special features: https://github.com/sqlalchemy/sqlalchemy/issues/7865 this will allow retunring(User) to send back an

Re: [sqlalchemy] How to infer the ORM model class from an update()/insert() object?

2022-03-28 Thread Mike Bayer
On Mon, Mar 28, 2022, at 1:31 PM, mkmo...@gmail.com wrote: > Hi Mike, > > When using `column_property`, this > `select(User).from_statement(ins.returing(User))` construct will not load in > the column property. Instead the ORM will issue a second query when the > column property is accessed.

Re: [sqlalchemy] How to infer the ORM model class from an update()/insert() object?

2022-03-28 Thread mkmo...@gmail.com
Hi Mike, When using `column_property`, this `select(User).from_statement(ins.returing(User))` construct will not load in the column property. Instead the ORM will issue a second query when the column property is accessed. I am able to get it working using the following:

Re: [sqlalchemy] How to infer the ORM model class from an update()/insert() object?

2022-03-27 Thread Mike Bayer
On Sun, Mar 27, 2022, at 2:56 PM, mkmo...@gmail.com wrote: > Hi Mike, > > I'm writing a library that uses SQLAlchemy. The user will pass the library an > update, and the library will add a RETURNING clause for postgresql users, and > then return the model back to the user. The idea here is to

Re: [sqlalchemy] How to infer the ORM model class from an update()/insert() object?

2022-03-27 Thread mkmo...@gmail.com
Hi Mike, I'm writing a library that uses SQLAlchemy. The user will pass the library an update, and the library will add a RETURNING clause for postgresql users, and then return the model back to the user. The idea here is to update and select the row in a single database call, instead of the

Re: [sqlalchemy] How to infer the ORM model class from an update()/insert() object?

2022-03-27 Thread Mike Bayer
On Sun, Mar 27, 2022, at 2:08 PM, mkmo...@gmail.com wrote: > Hi Mike, > > Thanks. Should I use column_descriptions[0]['type'] ? yup, that should be pretty consistent in this case. I've implemented most of an actual feature for this but isn't committed yet at

Re: [sqlalchemy] How to infer the ORM model class from an update()/insert() object?

2022-03-27 Thread mkmo...@gmail.com
Hi Mike, Thanks. Should I use column_descriptions[0]['type'] ? In my case, `type`, `expr` and `entity` all return the model class that I am interested in. Thanks and best regards, Matthew On Saturday, March 26, 2022 at 12:02:54 PM UTC-7 Mike Bayer wrote: > the Project model is actually in

Re: [sqlalchemy] How to infer the ORM model class from an update()/insert() object?

2022-03-26 Thread Mike Bayer
the Project model is actually in there, but not in a public API place (this is not the solution, but look inside of table._annotations to see it). The closest public API we have for this very new API right now is the Query equivalent of column_descriptions, which is available on the select()

[sqlalchemy] How to infer the ORM model class from an update()/insert() object?

2022-03-26 Thread mkmo...@gmail.com
Hello, How can I infer the ORM model class from an update (or insert, or delete) function result? upd = update(Project).values(name='foo').where( Project.id == 1 ) def my_library_function(session, upd): result = session.execute(upd) # how to get the Project ORM model here, using