Skip to content

working of insert_many vs multiple single inserts #453

Answered by billy1624
vikigenius asked this question in Q&A
Discussion options

You must be logged in to vote

Hey @vikigenius, just like what you have said. insert_many will construct SQL statement like that. And it will be sent to the database once only.

/// let apple = cake::ActiveModel {
/// name: Set("Apple Pie".to_owned()),
/// ..Default::default()
/// };
/// let orange = cake::ActiveModel {
/// name: Set("Orange Scone".to_owned()),
/// ..Default::default()
/// };
///
/// let insert_result = cake::Entity::insert_many(vec![apple, orange])
/// .exec(&db)
/// .await?;
///
/// assert_eq!(insert_result.last_insert_id, 28);
///
/// assert_eq!(
//…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by tyt2y3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #441 on January 13, 2022 17:40.