Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 9 additions & 11 deletions orch8-storage/src/postgres/mobile_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -571,20 +571,18 @@ impl crate::MobileSyncStore for PostgresStorage {
if command_ids.is_empty() {
return Ok(0);
}
let placeholders: Vec<String> = command_ids
.iter()
.enumerate()
.map(|(i, _)| format!("${}", i + 2))
.collect();
let sql = format!(
"UPDATE mobile_commands SET acked_at = now() WHERE device_id = $1 AND id IN ({})",
placeholders.join(",")
let mut qb = sqlx::QueryBuilder::new(
"UPDATE mobile_commands SET acked_at = now() WHERE device_id = ",
);
let mut query = sqlx::query(&sql).bind(device_id);
qb.push_bind(device_id);
qb.push(" AND id IN (");
let mut separated = qb.separated(", ");
for id in command_ids {
query = query.bind(id);
separated.push_bind(id);
}
let result = query
separated.push_unseparated(")");
let result = qb
.build()
.execute(&self.pool)
.await
.map_err(|e| StorageError::Query(e.to_string()))?;
Expand Down
16 changes: 9 additions & 7 deletions orch8-storage/src/sqlite/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2673,16 +2673,18 @@ impl crate::MobileSyncStore for SqliteStorage {
if command_ids.is_empty() {
return Ok(0);
}
let placeholders: Vec<&str> = command_ids.iter().map(|_| "?").collect();
let sql = format!(
"UPDATE mobile_commands SET acked_at = datetime('now') WHERE device_id = ? AND id IN ({})",
placeholders.join(",")
let mut qb: sqlx::QueryBuilder<'_, sqlx::Sqlite> = sqlx::QueryBuilder::new(
"UPDATE mobile_commands SET acked_at = datetime('now') WHERE device_id = ",
);
let mut query = sqlx::query(&sql).bind(device_id);
qb.push_bind(device_id);
qb.push(" AND id IN (");
let mut separated = qb.separated(", ");
for id in command_ids {
query = query.bind(id);
separated.push_bind(id);
}
let result = query
separated.push_unseparated(")");
let result = qb
.build()
.execute(&self.pool)
.await
.map_err(|e| StorageError::Query(e.to_string()))?;
Expand Down
Loading