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

Added InsertWithFallback so that empty iterators passed to Insert will be handled with a custom function of the users' choice #1682

Closed
wants to merge 1 commit into from

Conversation

asdfcube
Copy link

@asdfcube asdfcube commented Jun 1, 2023

PR Info

New Features

  • InsertWithFallback, a simple wrapper around Insert that checks if the iterator passed to the Insert is empty and run a function if it is true.
  • FallbackResult, a simple enum so that the user knows if the fallback was triggered or not.

… will be handled with a custom function of the users' choice
Comment on lines +309 to +310
/// On conflict
///
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These examples seems to have not related to the new feature?

Copy link
Member

@tyt2y3 tyt2y3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add some test cases to demo the API?

pub fn exec<'a, C>(
self,
db: &'a C,
) -> FallbackResult<R, impl Future<Output = Result<InsertResult<A>, DbErr>> + '_>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This certainly does not look like the right API
It should return impl Future<Output = Result<FallbackResult<InsertResult<A>>, DbErr>>

@tyt2y3
Copy link
Member

tyt2y3 commented Jun 2, 2023

Can we have something simpler, like:

let result: MaybeInsertResult<_> = Entity::insert_many(..).on_empty_do_nothing().exec(db).await?;

@tyt2y3
Copy link
Member

tyt2y3 commented Jun 11, 2023

We'll probably let @darkmmon take over the issue

@tyt2y3 tyt2y3 closed this Jun 11, 2023
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

Successfully merging this pull request may close these issues.

insert_many failing if the models iterator is empty
2 participants