fix: don't generate broken sql
This commit is contained in:
parent
57177612ec
commit
c7130bbcd4
6 changed files with 23 additions and 14 deletions
|
|
@ -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(())
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue