fix: don't generate broken sql

This commit is contained in:
Robert Perce 2026-02-04 13:07:26 -06:00
parent 57177612ec
commit c7130bbcd4
6 changed files with 23 additions and 14 deletions

View file

@ -129,19 +129,22 @@ pub async fn insert_mentions<'a>(
mentions: impl IntoIterator<Item = &'a Mention>,
pool: &SqlitePool,
) -> Result<(), AppError> {
let mut qb = QueryBuilder::<sqlx::Sqlite>::new(
"insert into mentions (
let mut mentions = mentions.into_iter().peekable();
if mentions.peek().is_some() {
let mut qb = QueryBuilder::<sqlx::Sqlite>::new(
"insert into mentions (
entity_id, entity_type, url, input_text,
byte_range_start, byte_range_end) ",
);
qb.push_values(mentions, |mut b, mention| {
b.push_bind(mention.entity_id)
.push_bind(mention.entity_type)
.push_bind(&mention.url)
.push_bind(&mention.input_text)
.push_bind(mention.byte_range_start)
.push_bind(mention.byte_range_end);
});
qb.build().execute(pool).await?;
);
qb.push_values(mentions, |mut b, mention| {
b.push_bind(mention.entity_id)
.push_bind(mention.entity_type)
.push_bind(&mention.url)
.push_bind(&mention.input_text)
.push_bind(mention.byte_range_start)
.push_bind(mention.byte_range_end);
});
qb.build().execute(pool).await?;
}
Ok(())
}