diff --git a/sea-orm-sync/src/query/insert.rs b/sea-orm-sync/src/query/insert.rs
index 3d22b5470..dedeab208 100644
--- a/sea-orm-sync/src/query/insert.rs
+++ b/sea-orm-sync/src/query/insert.rs
@@ -348,7 +348,8 @@ where
self
}
- /// Allow insert statement to return without error if nothing's been inserted
+ /// Convert self into `TryInsert`, which can handle conflicted inserts.
+ #[deprecated(since = "2.0.0", note = "Please use [`InsertMany::try_insert`]")]
pub fn do_nothing(self) -> TryInsert
where
A: ActiveModelTrait,
@@ -356,7 +357,16 @@ where
TryInsert::from_many(self)
}
- /// Alias to `do_nothing`
+ /// Convert self into `TryInsert`, which can handle conflicted inserts.
+ pub fn try_insert(self) -> TryInsert
+ where
+ A: ActiveModelTrait,
+ {
+ TryInsert::from_many(self)
+ }
+
+ /// Alias to `try_insert`. Since 2.0 you don't need this anymore, because
+ /// `InsertManyResult` would return `last_insert_id` as `None`.
pub fn on_empty_do_nothing(self) -> TryInsert
where
A: ActiveModelTrait,
diff --git a/sea-orm-sync/tests/upsert_tests.rs b/sea-orm-sync/tests/upsert_tests.rs
index b9912e9b4..b6dbc7858 100644
--- a/sea-orm-sync/tests/upsert_tests.rs
+++ b/sea-orm-sync/tests/upsert_tests.rs
@@ -68,7 +68,7 @@ pub fn create_insert_default(db: &DatabaseConnection) -> Result<(), DbErr> {
let res = Entity::insert_many([ActiveModel { id: Set(3) }, ActiveModel { id: Set(4) }])
.on_conflict(on_conflict)
- .do_nothing()
+ .try_insert()
.exec(db);
assert!(matches!(res, Ok(TryInsertResult::Conflicted)));
diff --git a/src/query/insert.rs b/src/query/insert.rs
index 40b8bcbef..d3e5d1ca2 100644
--- a/src/query/insert.rs
+++ b/src/query/insert.rs
@@ -348,7 +348,8 @@ where
self
}
- /// Allow insert statement to return without error if nothing's been inserted
+ /// Convert self into `TryInsert`, which can handle conflicted inserts.
+ #[deprecated(since = "2.0.0", note = "Please use [`InsertMany::try_insert`]")]
pub fn do_nothing(self) -> TryInsert
where
A: ActiveModelTrait,
@@ -356,7 +357,16 @@ where
TryInsert::from_many(self)
}
- /// Alias to `do_nothing`
+ /// Convert self into `TryInsert`, which can handle conflicted inserts.
+ pub fn try_insert(self) -> TryInsert
+ where
+ A: ActiveModelTrait,
+ {
+ TryInsert::from_many(self)
+ }
+
+ /// Alias to `try_insert`. Since 2.0 you don't need this anymore, because
+ /// `InsertManyResult` would return `last_insert_id` as `None`.
pub fn on_empty_do_nothing(self) -> TryInsert
where
A: ActiveModelTrait,
diff --git a/tests/upsert_tests.rs b/tests/upsert_tests.rs
index 539f2322e..2e383c8ac 100644
--- a/tests/upsert_tests.rs
+++ b/tests/upsert_tests.rs
@@ -73,7 +73,7 @@ pub async fn create_insert_default(db: &DatabaseConnection) -> Result<(), DbErr>
let res = Entity::insert_many([ActiveModel { id: Set(3) }, ActiveModel { id: Set(4) }])
.on_conflict(on_conflict)
- .do_nothing()
+ .try_insert()
.exec(db)
.await;