-
-
Notifications
You must be signed in to change notification settings - Fork 520
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
Support returning clause to avoid database hits #183
Comments
Sounds good to me! But note that only Postgres support |
To deal with that we have some options:
I would first implement strategy one and then with more time implement strategy 2. Why? Because postgres users like me are likely to need it soon and we can give the bonus to non postgres users latter. What do you think? |
related: #148 |
Reasonable!! @marlon-sousa |
Just to summarise the support of Postgres
MySQL
MariaDB
SQLite
|
Hello,
I took a look at discussions and haven't found nothing, so I am opening this issue to discuss something important.
We need to support returning clauses in updates and insert clauses.
Rationale
Sometimes, we need to perform batch operations, by means of multiple inserts or updates which affect more than one record and, at the same time, have the newly inserted / the updated records back in the same database operation.
This is needed, for example, when you need to insert records and have their auto incremented generated ids back to store somewhere for latter use, or when you need to update one or more records and, at the same time, get back columns you didn't have when you performed the update operation.
The way sql handles this is by using a returning clause on the query, making the database, in one operation, perform inserts / updates and also returning information you need instead of forcing you to make a latter select.
Proposal
We propose an extension to the current sea-orm api.
update_many
The UpdateMany struct should have another method, called returning.
Kind of code below
RecordInfo should be an enum like
The returning function would generate a returning sql clause, as follows:
The insert_many would go the very same path.
The ExecResult would need to ave a vector of ActiveModels with the appropriate columns set for each returned record.
What do you think?
I could try to implement that, I would need some mentoring but I am now more focused in stablishing the api, latter we can think in the implementation.
The text was updated successfully, but these errors were encountered: