Conversation
Member
Author
|
Summary of changes:
|
tyt2y3
commented
Jun 16, 2025
Comment on lines
+24
to
+32
| let res = Entity::insert_many::<ActiveModel, _>([]).exec(db).await; | ||
|
|
||
| assert_eq!(res?.last_insert_id, None); | ||
|
|
||
| let res = Entity::insert_many([ActiveModel { id: Set(1) }, ActiveModel { id: Set(2) }]) | ||
| .exec(db) | ||
| .await; | ||
|
|
||
| assert_eq!(res?.last_insert_id, Some(2)); |
Member
Author
There was a problem hiding this comment.
best to look at this file for illustration
tyt2y3
commented
Jun 16, 2025
Comment on lines
+108
to
+114
| assert!( | ||
| Entity::insert_many::<ActiveModel, _>([]) | ||
| .exec_with_returning(db) | ||
| .await | ||
| .unwrap() | ||
| .is_empty() | ||
| ); |
Expurple
approved these changes
Jun 16, 2025
| A: ActiveModelTrait, | ||
| { | ||
| /// The id performed when AUTOINCREMENT was performed on the PrimaryKey | ||
| pub last_insert_id: Option<<PrimaryKey<A> as PrimaryKeyTrait>::ValueType>, |
Member
There was a problem hiding this comment.
This type makes a lot of sense. The PR is worth it, in my opinion
Comment on lines
+57
to
+60
| /// Empty: `Ok(None)`. Inserted: `Ok(Some(last_insert_id))`. Conflicted: `Err(DbErr::RecordNotInserted)`. | ||
| pub fn last_insert_id( | ||
| self, | ||
| ) -> Result<Option<<PrimaryKey<A> as PrimaryKeyTrait>::ValueType>, DbErr> { |
tyt2y3
commented
Jun 16, 2025
Comment on lines
+301
to
+303
| /// # Panics | ||
| /// | ||
| /// Panics if the database backend does not support `INSERT RETURNING`. |
Member
Author
There was a problem hiding this comment.
I'll replace the panics with BackendNotSupported in a later PR
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
end goal is to add a new struct for InsertMany, diverging from current Insert