Skip to content

Commit

Permalink
on conflict do nothing SeaQL/sea-orm#1712
Browse files Browse the repository at this point in the history
  • Loading branch information
darkmmon committed Jul 12, 2023
1 parent 4927f25 commit 4175aa9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion SeaORM/docs/0.12.x-CHANGELOG_temp.md
Expand Up @@ -304,7 +304,6 @@ let res = Bakery::insert_many(std::iter::empty())

assert!(matches!(res, Ok(TryInsertResult::Empty)));
```
================================ All Changes above was being Documented ================================
* On conflict do nothing not resulting in Err https://github.com/SeaQL/sea-orm/pull/1712
```rust
let on = OnConflict::column(Column::Id).do_nothing().to_owned();
Expand All @@ -317,6 +316,7 @@ assert!(matches!(res, Err(DbErr::RecordNotInserted)));
let res = Entity::insert_many([..]).on_conflict(on).do_nothing().exec(db).await;
assert!(matches!(res, Ok(TryInsertResult::Conflicted)));
```
================================ All Changes above was being Documented ================================

### Upgrades

Expand Down
14 changes: 14 additions & 0 deletions SeaORM/docs/05-basic-crud/03-insert.md
Expand Up @@ -286,3 +286,17 @@ let res = Entity::insert_many([

assert_eq!(res.err(), Some(DbErr::RecordNotInserted));
```

Or you can use `.do_nothing()` to return safely instead.

```rust
let on = OnConflict::column(Column::Id).do_nothing().to_owned();

// Existing behaviour
let res = Entity::insert_many([..]).on_conflict(on).exec(db).await;
assert!(matches!(res, Err(DbErr::RecordNotInserted)));

// you can also:
let res = Entity::insert_many([..]).on_conflict(on).do_nothing().exec(db).await;
assert!(matches!(res, Ok(TryInsertResult::Conflicted)));
```

0 comments on commit 4175aa9

Please sign in to comment.