Skip to content

Commit

Permalink
Use insert and update on duplicate instead of replace (#421)
Browse files Browse the repository at this point in the history
  • Loading branch information
dlen authored Sep 21, 2024
1 parent 5d84489 commit d348630
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion packages/apalis-sql/src/mysql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,13 +177,14 @@ impl<T: DeserializeOwned + Send + Unpin + Job + Sync + 'static> MysqlStorage<T>
let worker_type = T::NAME;
let storage_name = std::any::type_name::<Self>();
let query =
"REPLACE INTO workers (id, worker_type, storage_name, layers, last_seen) VALUES (?, ?, ?, ?, ?);";
"INSERT INTO workers (id, worker_type, storage_name, layers, last_seen) VALUES (?, ?, ?, ?, ?) ON DUPLICATE KEY UPDATE id = ?;";
sqlx::query(query)
.bind(worker_id.to_string())
.bind(worker_type)
.bind(storage_name)
.bind(std::any::type_name::<Service>())
.bind(last_seen)
.bind(worker_id.to_string())
.execute(&mut *tx)
.await?;
Ok(())
Expand Down

0 comments on commit d348630

Please sign in to comment.