When inserting data in batches, it is desired to return the number of successfully inserted data
Open
Nobody has claimed this yet.
Area:crud
- Dominant language
- Rust
- Stars
- 9.9k
- Forks
- 734
- Avg merge
- 6h 36m
- Merged PRs (30d)
- 8
Description
pub async fn insert_batch(db: &DbConn, list: &Vec<RoleMenuMergeSaveDTO>) -> Result<u64, DbErr> {
let result: Vec<role_menu_merge::ActiveModel> = list.iter().map(|item| role_menu_merge::ActiveModel {
menu_id: Set(item.menu_id),
role_id: Set(item.role_id),
create_time: Set(Option::from(chrono::Local::now().naive_local().to_owned())),
update_time: Set(Option::from(chrono::Local::now().naive_local().to_owned())),
..Default::default()
}).collect();
let insert_result = RoleMenuMerge::insert_many(result)
.exec(db)
.await?;
Ok(insert_result.last_insert_id)
}
For example, in the above code, I want to return the number of successfully inserted entries, but it seems that it cannot be implemented at the moment. Can we add a method similar to rows_affected?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the insert_many(...).exec(db) entry point and inspect the execution result used by the example. Compare it with any existing rows_affected behavior; done means batch insertion can expose the number of successfully inserted entries while preserving last_insert_id behavior, with coverage for the new result.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- databases
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100