This commit is contained in:
Billy Chan 2024-06-19 20:40:18 +08:00
parent bca933a055
commit 1c03a28c8a
No known key found for this signature in database
GPG Key ID: 45461E52F22E0279

View File

@ -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,