(
&self,
object_type: &str,
id: &str,
expected_resource_version: u64,
)
| 229 | } |
| 230 | |
| 231 | pub async fn delete_if( |
| 232 | &self, |
| 233 | object_type: &str, |
| 234 | id: &str, |
| 235 | expected_resource_version: u64, |
| 236 | ) -> PersistenceResult<bool> { |
| 237 | let result = sqlx::query( |
| 238 | r#" |
| 239 | DELETE FROM "objects" |
| 240 | WHERE "object_type" = ?1 AND "id" = ?2 AND "resource_version" = ?3 |
| 241 | "#, |
| 242 | ) |
| 243 | .bind(object_type) |
| 244 | .bind(id) |
| 245 | .bind(i64::try_from(expected_resource_version).unwrap_or(i64::MAX)) |
| 246 | .execute(&self.pool) |
| 247 | .await |
| 248 | .map_err(|e| map_db_error(&e))?; |
| 249 | |
| 250 | if result.rows_affected() > 0 { |
| 251 | Ok(true) |
| 252 | } else { |
| 253 | // Check if object exists to distinguish NotFound from Conflict |
| 254 | let existing = self.get(object_type, id).await?; |
| 255 | if let Some(record) = existing { |
| 256 | return Err(PersistenceError::Conflict { |
| 257 | current_resource_version: Some(record.resource_version), |
| 258 | }); |
| 259 | } |
| 260 | Ok(false) |
| 261 | } |
| 262 | } |
| 263 | |
| 264 | pub async fn put_scoped( |
| 265 | &self, |
nothing calls this directly
no test coverage detected