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

Method list_with_selector

crates/openshell-server/src/persistence/postgres.rs:398–429  ·  view source on GitHub ↗
(
        &self,
        object_type: &str,
        label_selector: &str,
        limit: u32,
        offset: u32,
    )

Source from the content-addressed store, hash-verified

396 }
397
398 pub async fn list_with_selector(
399 &self,
400 object_type: &str,
401 label_selector: &str,
402 limit: u32,
403 offset: u32,
404 ) -> PersistenceResult<Vec<ObjectRecord>> {
405 use super::parse_label_selector;
406
407 let required_labels = parse_label_selector(label_selector)?;
408 let labels_jsonb = serde_json::to_value(&required_labels)
409 .map_err(|e| PersistenceError::Encode(format!("failed to serialize labels: {e}")))?;
410
411 let rows = sqlx::query(
412 r"
413SELECT object_type, id, name, payload, created_at_ms, updated_at_ms, labels, resource_version
414FROM objects
415WHERE object_type = $1 AND labels @> $2
416ORDER BY created_at_ms ASC, name ASC
417LIMIT $3 OFFSET $4
418",
419 )
420 .bind(object_type)
421 .bind(&labels_jsonb)
422 .bind(i64::from(limit))
423 .bind(i64::from(offset))
424 .fetch_all(&self.pool)
425 .await
426 .map_err(|e| map_db_error(&e))?;
427
428 Ok(rows.into_iter().map(row_to_object_record).collect())
429 }
430
431 pub async fn put_policy_revision(
432 &self,

Callers

nothing calls this directly

Calls 2

parse_label_selectorFunction · 0.85
map_db_errorFunction · 0.85

Tested by

no test coverage detected