igorbenav / fastcrud

FastCRUD is a Python package for FastAPI, offering robust async CRUD operations and flexible endpoint creation utilities.
MIT License
530 stars 32 forks source link

Return model on update #106

Open feluelle opened 1 week ago

feluelle commented 1 week ago

Is your feature request related to a problem? Please describe.

When performing an update, I am missing the option to retrieve the updated model. I explicitly have to get the updated model from the DB.

Describe the solution you'd like

I would like to leverage the sqlalchemy Update returning clause which allows returning the data after the update has been performed.

JakNowy commented 4 days ago

That's a good point and should be pretty simple to implement. Would you like to work on it maybe?

Let's add optional returning parameter as a list of fields and chain the stmt with .returning if it's present.

feluelle commented 4 days ago

Yes, I can give it a try. :)

feluelle commented 4 days ago

Unfortunately, that would probably mean we need to remove the commit arg and ideally we do the same as we do for get and return the data as a model. I would even suggest we split the current function into update and update_multi.