From 1c03a28c8aab3515d1fa42e43048485e8ab33203 Mon Sep 17 00:00:00 2001 From: Billy Chan Date: Wed, 19 Jun 2024 20:40:18 +0800 Subject: [PATCH] docs --- src/query/insert.rs | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/src/query/insert.rs b/src/query/insert.rs index 457d1d1e..57e05fb4 100644 --- a/src/query/insert.rs +++ b/src/query/insert.rs @@ -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 where A: ActiveModelTrait,