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

Method put_draft_chunk

crates/openshell-server/src/persistence/sqlite.rs:650–685  ·  view source on GitHub ↗
(
        &self,
        chunk: &DraftChunkRecord,
        dedup_key: Option<&str>,
    )

Source from the content-addressed store, hash-verified

648 }
649
650 pub async fn put_draft_chunk(
651 &self,
652 chunk: &DraftChunkRecord,
653 dedup_key: Option<&str>,
654 ) -> PersistenceResult<String> {
655 let payload = draft_chunk_payload_from_record(chunk)?;
656 // RETURNING "id" gives us the row's effective id regardless of
657 // whether INSERT inserted a fresh row or ON CONFLICT updated an
658 // existing one. Callers report this id to clients so the response
659 // can never advertise a chunk_id that isn't actually persisted.
660 let row = sqlx::query(
661 r#"
662INSERT INTO "objects" (
663 "object_type", "id", "scope", "status", "dedup_key", "hit_count", "payload", "created_at_ms", "updated_at_ms"
664)
665VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9)
666ON CONFLICT ("object_type", "scope", "dedup_key") WHERE "dedup_key" IS NOT NULL DO UPDATE SET
667 "hit_count" = "objects"."hit_count" + excluded."hit_count",
668 "updated_at_ms" = excluded."updated_at_ms"
669RETURNING "id"
670"#,
671 )
672 .bind(DRAFT_CHUNK_OBJECT_TYPE)
673 .bind(&chunk.id)
674 .bind(&chunk.sandbox_id)
675 .bind(&chunk.status)
676 .bind(dedup_key)
677 .bind(i64::from(chunk.hit_count))
678 .bind(payload)
679 .bind(chunk.first_seen_ms)
680 .bind(chunk.last_seen_ms)
681 .fetch_one(&self.pool)
682 .await
683 .map_err(|e| map_db_error(&e))?;
684 Ok(row.get::<String, _>("id"))
685 }
686
687 pub async fn get_draft_chunk(&self, id: &str) -> PersistenceResult<Option<DraftChunkRecord>> {
688 let row = sqlx::query(

Calls 2

map_db_errorFunction · 0.85

Tested by

no test coverage detected