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]: Addition of delete many #615

Open
AbhijithGanesh opened this issue Mar 16, 2022 · 4 comments
Open

[ADD]: Addition of delete many #615

AbhijithGanesh opened this issue Mar 16, 2022 · 4 comments
Assignees

Comments

@AbhijithGanesh
Copy link

Summary

Delete the row(s) on db at the same time returning the data of deleted row(s).

Motivation

Various other delete methods, this method is a good method to implement as it makes the ORM more complete.

Additional Information

Rough idea is that we need two new methods in DeleteMany, https://github.com/SeaQL/sea-orm/blob/af235168db3a675e889974a34799890350be00e4/src/executor/delete.rs#L34-L46, namely one & all which return single model & array of models respectively. For database support RETURNING, https://docs.rs/sea-orm/0.6.0/sea_orm/query/trait.ConnectionTrait.html#method.support_returning, it will use RETURNING syntax on delete statement to get the data of deleted models.

@AbhijithGanesh
Copy link
Author

@billy1624 can you please assign this to me?

@billy1624
Copy link
Member

Assigned! :P

@billy1624
Copy link
Member

Hey @AbhijithGanesh,

Rough idea is that we need two new methods in DeleteMany, namely one & all which return single model & array of models respectively.

impl<'a, E> DeleteMany<E>
where
E: EntityTrait,
{
/// Execute a DELETE operation on many ActiveModels
pub fn exec<C>(self, db: &'a C) -> impl Future<Output = Result<DeleteResult, DbErr>> + '_
where
C: ConnectionTrait,
{
// so that self is dropped before entering await
exec_delete_only(self.query, db)
}
}

For database support RETURNING, it will use RETURNING syntax on delete statement to get the data of deleted models.

@billy1624 billy1624 moved this to Triage in SeaQL Dev Tracker Jul 8, 2022
@billy1624 billy1624 moved this from Triage to Open for Contributions in SeaQL Dev Tracker Jul 8, 2022
@billy1624 billy1624 moved this from Open for Contributions to Triage in SeaQL Dev Tracker Jan 13, 2023
@tyt2y3
Copy link
Member

tyt2y3 commented Feb 22, 2025

I think this has partially been solved by 008f844

although for delete one, it's possible that we pass-through the primary key (like insert) and do a second query if backend does not support returning

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

Successfully merging a pull request may close this issue.

3 participants