#need help with sqlx mysql transaction

4 messages · Page 1 of 1 (latest)

sterile knoll
#

this is my code


    let pool = MySqlPoolOptions::new()
        .max_connections(5)
        .connect(&database_url)
        .await?;

    let mut transaction = pool.begin().await?;

    let product_h = sqlx::query("INSERT INTO product_h VALUES (null, ?, ?, 0)")
        .bind(product_barcode)
        .bind(product_name)
        .execute(&mut transaction)
        .await?;

    for item in product_category_sub {
        let result = sqlx::query("INSERT INTO product_d VALUES (null, ?, ?, ?, 0)")
            .bind(product_h.last_insert_id())
            .bind(item.product_category_sub_name)
            .bind(100000)
            .execute(&mut transaction)
            .await?;

        if let Err(e) = result {
            transaction.rollback().await?;
            println!("Error inserting data: {:?}", e);
        }
    }

    transaction.commit().await?;```
#

im getting error like this

#

at the stack overlfow they said add * at the &mut transaction

#

but i get this type of error