(
&self,
object_type: &str,
id: &str,
expected_resource_version: u64,
)
| 208 | } |
| 209 | |
| 210 | pub async fn delete_if( |
| 211 | &self, |
| 212 | object_type: &str, |
| 213 | id: &str, |
| 214 | expected_resource_version: u64, |
| 215 | ) -> PersistenceResult<bool> { |
| 216 | let result = sqlx::query( |
| 217 | r" |
| 218 | DELETE FROM objects |
| 219 | WHERE object_type = $1 AND id = $2 AND resource_version = $3 |
| 220 | ", |
| 221 | ) |
| 222 | .bind(object_type) |
| 223 | .bind(id) |
| 224 | .bind(i64::try_from(expected_resource_version).unwrap_or(i64::MAX)) |
| 225 | .execute(&self.pool) |
| 226 | .await |
| 227 | .map_err(|e| map_db_error(&e))?; |
| 228 | |
| 229 | if result.rows_affected() > 0 { |
| 230 | Ok(true) |
| 231 | } else { |
| 232 | // Check if object exists to distinguish NotFound from Conflict |
| 233 | let existing = self.get(object_type, id).await?; |
| 234 | if let Some(record) = existing { |
| 235 | Err(PersistenceError::Conflict { |
| 236 | current_resource_version: Some(record.resource_version), |
| 237 | }) |
| 238 | } else { |
| 239 | Ok(false) |
| 240 | } |
| 241 | } |
| 242 | } |
| 243 | |
| 244 | pub async fn put_scoped( |
| 245 | &self, |
nothing calls this directly
no test coverage detected