Skip to content

Commit

Permalink
on empty do nothing SeaQL/sea-orm#1708
Browse files Browse the repository at this point in the history
  • Loading branch information
darkmmon committed Jul 12, 2023
1 parent 899dc96 commit 4927f25
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion SeaORM/docs/0.12.x-CHANGELOG_temp.md
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,6 @@ assert_eq!(migration.status(), MigrationStatus::Pending);
assert!(matches!(db.ping().await, Err(DbErr::ConnectionAcquire)));
}
```
================================ All Changes above was being Documented ================================
* Added `TryInsert` that does not panic on empty inserts https://github.com/SeaQL/sea-orm/pull/1708
```rust
// now, you can do:
Expand All @@ -305,6 +304,7 @@ 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 Down
17 changes: 17 additions & 0 deletions SeaORM/docs/05-basic-crud/03-insert.md
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,23 @@ let res: InsertResult = Fruit::insert_many([apple, orange]).exec(db).await?;
assert_eq!(res.last_insert_id, 30)
```

### Failing Insertion

## on empty

Normally it will return an error if the Insert statement is empty.
However, you can change the behaviour with `.on_empty_do_nothing()` method.

```rust
// now, you can do:
let res = Bakery::insert_many(std::iter::empty())
.on_empty_do_nothing()
.exec(db)
.await;

assert!(matches!(res, Ok(TryInsertResult::Empty)));
```

## On Conflict

Insert active model with on conflict behaviour.
Expand Down

0 comments on commit 4927f25

Please sign in to comment.