Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions sea-orm-sync/src/query/insert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -348,15 +348,25 @@ 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<A>
where
A: ActiveModelTrait,
{
TryInsert::from_many(self)
}

/// Alias to `do_nothing`
/// Convert self into `TryInsert`, which can handle conflicted inserts.
pub fn try_insert(self) -> TryInsert<A>
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<A>
where
A: ActiveModelTrait,
Expand Down
2 changes: 1 addition & 1 deletion sea-orm-sync/tests/upsert_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
Expand Down
14 changes: 12 additions & 2 deletions src/query/insert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -348,15 +348,25 @@ 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<A>
where
A: ActiveModelTrait,
{
TryInsert::from_many(self)
}

/// Alias to `do_nothing`
/// Convert self into `TryInsert`, which can handle conflicted inserts.
pub fn try_insert(self) -> TryInsert<A>
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<A>
where
A: ActiveModelTrait,
Expand Down
2 changes: 1 addition & 1 deletion tests/upsert_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Loading