SeaQL / SeaQL/sea-orm

When inserting data in batches, it is desired to return the number of successfully inserted data

Open
#2,535 1 comment 1 reaction 0 assignees View on GitHub

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.