MCPcopy Create free account
hub / github.com/NVIDIA/OpenShell / delete_if

Method delete_if

crates/openshell-server/src/persistence/postgres.rs:210–242  ·  view source on GitHub ↗
(
        &self,
        object_type: &str,
        id: &str,
        expected_resource_version: u64,
    )

Source from the content-addressed store, hash-verified

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"
218DELETE FROM objects
219WHERE 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,

Callers

nothing calls this directly

Calls 2

map_db_errorFunction · 0.85
getMethod · 0.45

Tested by

no test coverage detected