how can I perform a batch upsert for sqlite? #4545
-
Hi I am relatively new to rust. I am trying to generate a function that allows me to perform an insert or update in batches, trying to use on_clonfict do_update for sqlite. I validate the conflict by the id because the id I build it, it is not auto incremental, so that when it identifies that this id already exists but comes in the vector of records it will update it, and if it does not exist it will create it. this is my implementation: pub fn synchronize_payment_term(
conn: &mut SqliteConnection,
payments: Vec<PaymentTerm>,
) -> QueryResult<usize> {
use crate::models::schema::payment_term::dsl::*;
let rows_affected = diesel::insert_into(payment_term)
.values(payments)
.on_conflict(id)
.do_update()
.set((
name.eq(excluded(name)),
active.eq(excluded(active)),
description.eq(excluded(description)),
code.eq(excluded(code)),
payment_type.eq(excluded(payment_type)),
create_date.eq(excluded(create_date)),
write_date.eq(excluded(write_date)),
))
.execute(conn)?;
Ok(rows_affected)
} but when I do this, I get the following problem
the currently sqlite does not support to perform the upsert action in batches? any idea how I could do this? for performance reasons I would not want to iterate over the vector to do it one by one. Versions
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
You need to add a |
Beta Was this translation helpful? Give feedback.
Turns out there was a missing impl for this to work. I've opened #4546 to fix that.