Skip to content

Commit

Permalink
docs
Browse files Browse the repository at this point in the history
  • Loading branch information
billy1624 committed Jun 19, 2024
1 parent bca933a commit 1c03a28
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion src/query/insert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,38 @@ where
TryInsert::from_insert(self)
}

/// On conflict do nothing
/// Set ON CONFLICT do nothing, but with MySQL specific polyfill.
///
/// ```
/// use sea_orm::{entity::*, query::*, sea_query::OnConflict, tests_cfg::cake, DbBackend};
///
/// let orange = cake::ActiveModel {
/// id: ActiveValue::set(2),
/// name: ActiveValue::set("Orange".to_owned()),
/// };
///
/// assert_eq!(
/// cake::Entity::insert(orange.clone())
/// .on_conflict_do_nothing()
/// .build(DbBackend::MySql)
/// .to_string(),
/// r#"INSERT INTO `cake` (`id`, `name`) VALUES (2, 'Orange') ON DUPLICATE KEY UPDATE `id` = `id`"#,
/// );
/// assert_eq!(
/// cake::Entity::insert(orange.clone())
/// .on_conflict_do_nothing()
/// .build(DbBackend::Postgres)
/// .to_string(),
/// r#"INSERT INTO "cake" ("id", "name") VALUES (2, 'Orange') ON CONFLICT ("id") DO NOTHING"#,
/// );
/// assert_eq!(
/// cake::Entity::insert(orange)
/// .on_conflict_do_nothing()
/// .build(DbBackend::Sqlite)
/// .to_string(),
/// r#"INSERT INTO "cake" ("id", "name") VALUES (2, 'Orange') ON CONFLICT ("id") DO NOTHING"#,
/// );
/// ```
pub fn on_conflict_do_nothing(mut self) -> TryInsert<A>
where
A: ActiveModelTrait,
Expand Down

0 comments on commit 1c03a28

Please sign in to comment.