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

Do nothing on conflict #1712

Merged
merged 2 commits into from
Jun 21, 2023
Merged

Do nothing on conflict #1712

merged 2 commits into from
Jun 21, 2023

Conversation

darkmmon
Copy link
Contributor

PR Info

  • Closes
  • Dependents:

New Features

  • added conflicted to TryInsert return type.

Changes

  • updated docs on TryInsert

if temp.is_err()
&& temp.as_ref().expect_err("must be error by previous check")
== &DbErr::RecordNotInserted
{
Copy link
Member

Choose a reason for hiding this comment

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

May be you can try the match syntax:

if matches!(temp, Err(DbErr::RecordNotInserted))

@tyt2y3
Copy link
Member

tyt2y3 commented Jun 20, 2023

Please rebase this branch onto master;
Please do not merge master into this branch.

@darkmmon darkmmon force-pushed the do-nothing-on-conflict branch from 0bfc031 to 240ec4f Compare June 20, 2023 10:59
Comment on lines 52 to 61
if self.insert_struct.columns.is_empty() {
TryInsertResult::Empty
} else {
TryInsertResult::Inserted(self.insert_struct.exec(db).await)
let temp = self.insert_struct.exec(db).await;
if matches!(temp, Err(DbErr::RecordNotInserted)) {
TryInsertResult::Conflicted
} else {
TryInsertResult::Inserted(temp)
}
}
Copy link
Member

@billy1624 billy1624 Jun 21, 2023

Choose a reason for hiding this comment

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

Coding Style: maybe an early return over nested if ...?

if self.insert_struct.columns.is_empty() {
    return TryInsertResult::Empty
} 
let temp = self.insert_struct.exec(db).await;
if matches!(temp, Err(DbErr::RecordNotInserted)) {
    TryInsertResult::Conflicted
} else {
    TryInsertResult::Inserted(temp)
}

Same applied to the methods below

Copy link
Member

@tyt2y3 tyt2y3 Jun 21, 2023

Choose a reason for hiding this comment

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

yeah, that would look slightly better, and temp is better named as res

@tyt2y3
Copy link
Member

tyt2y3 commented Jun 21, 2023

@darkmmon As I said under this situation you should not merge master in, you should rebase on top of master.

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.

Will be good to go after addressing the above comments

clippy changes

fmt

change from basic if statement to matches
@darkmmon darkmmon force-pushed the do-nothing-on-conflict branch from 1d1f556 to 959146d Compare June 21, 2023 10:16
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.

Looks nice

@tyt2y3
Copy link
Member

tyt2y3 commented Jun 21, 2023

#1549

@tyt2y3 tyt2y3 merged commit 6e79501 into SeaQL:master Jun 21, 2023
darkmmon added a commit to darkmmon/seaql.github.io that referenced this pull request Jul 12, 2023
billy1624 added a commit to SeaQL/seaql.github.io that referenced this pull request Jul 19, 2023
* Optional Field SeaQL/sea-orm#1513

* .gitignore SeaQL/sea-orm#1334

* migration table custom name SeaQL/sea-orm#1511

* OR condition relation SeaQL/sea-orm#1433

* DerivePartialModel SeaQL/sea-orm#1597

* space for migration file naming SeaQL/sea-orm#1570

* composite key up to 12 SeaQL/sea-orm#1508

* seaography integration SeaQL/sea-orm#1599

* QuerySelect SimpleExpr SeaQL/sea-orm#1702

* sqlErr SeaQL/sea-orm#1707

* migration check SeaQL/sea-orm#1519

* postgres array SeaQL/sea-orm#1565

* param intoString SeaQL/sea-orm#1439

* **skipped** re-export SeaQL/sea-orm#1661

* ping SeaQL/sea-orm#1627

* on empty do nothing SeaQL/sea-orm#1708

* on conflict do nothing SeaQL/sea-orm#1712

* **skipped** upgrade versions

* active enum fail safe SeaQL/sea-orm#1374

* relation generation check SeaQL/sea-orm#1435

* entity generation bug SeaQL/sea-schema#105

* **skipped** bug fix that does not require edits

* EnumIter change SeaQL/sea-orm#1535

* completed and fixed a previous todo SeaQL/sea-orm#1570

* amended wordings and structures

* Edit

* Remove temp file

---------

Co-authored-by: Billy Chan <[email protected]>
@github-actions
Copy link

github-actions bot commented Aug 2, 2023

🎉 Released In 0.12.1 🎉

Thank you everyone for the contribution!
This feature is now available in the latest release. Now is a good time to upgrade!
Your participation is what makes us unique; your adoption is what drives us forward.
You can support SeaQL 🌊 by starring our repos, sharing our libraries and becoming a sponsor ⭐.

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.

3 participants