Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add into_model() for Insert/Update/Delete #148

Closed
nicoulaj opened this issue Sep 10, 2021 · 7 comments
Closed

Add into_model() for Insert/Update/Delete #148

nicoulaj opened this issue Sep 10, 2021 · 7 comments

Comments

@nicoulaj
Copy link

It is a common need to insert/update/delete and select some return columns as a single query. Currently sea-orm does not make this easy, so I think having ideally into_model() for Insert/Update/Delete would be very convenient. What do you think ?

@nicoulaj
Copy link
Author

related: SeaQL/sea-query#120

@billy1624
Copy link
Member

  1. I'm thinking how we handle databases that don't support returning? Should we just return the original ActiveModel passed into insert / update / delete?

  2. Also, what will be returned if we insert / update / delete multiple records? Or this into_model() method is not supported for insert / update / delete multiple records.

@nicoulaj
Copy link
Author

I'm thinking how we handle databases that don't support returning? Should we just return the original ActiveModel passed into insert / update / delete?

Indeed, it looks like this is supported by postgres, sqlite and mariadb but not mysql... Maybe use a feature flag ?

Also, what will be returned if we insert / update / delete multiple records? Or this into_model() method is not supported for insert / update / delete multiple records.

I don't see how this is different from normal select ? into_model() returns a Selector, Selector::all() returns a Vec. But maybe I am missing something.

@marlon-sousa
Copy link

Hello,

Can you post a pseldo_code to demonstrate how this should work?

I am interested in the api level, not in implementations.

For me, ideally, insert_many and update_many should always return a compound struct with number of affected rows and a vec of returned records, containg activemodel with the columns the querier asked for or an empty vector otherwise.

This would be the clearer way to let everyone to know what is going on in a way that is not so magical that is not intuitive unless you know the framework and is not so low level that makes code umreadable from the user point of view.

@tqwewe
Copy link
Contributor

tqwewe commented Oct 17, 2021

Is this related?
#240

@nicoulaj
Copy link
Author

nicoulaj commented Feb 8, 2022

I think this issue can be closed since #183 handled it ?

@billy1624
Copy link
Member

Ty!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants