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

Method put_draft_chunk

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

Source from the content-addressed store, hash-verified

627 }
628
629 pub async fn put_draft_chunk(
630 &self,
631 chunk: &DraftChunkRecord,
632 dedup_key: Option<&str>,
633 ) -> PersistenceResult<String> {
634 let payload = draft_chunk_payload_from_record(chunk)?;
635 // RETURNING id gives the row's effective id whether INSERT inserted
636 // a fresh row or ON CONFLICT updated an existing one. See the
637 // matching sqlite path for the rationale.
638 let row = sqlx::query(
639 r"
640INSERT INTO objects (
641 object_type, id, scope, status, dedup_key, hit_count, payload, created_at_ms, updated_at_ms
642)
643VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)
644ON CONFLICT (object_type, scope, dedup_key) WHERE dedup_key IS NOT NULL DO UPDATE SET
645 hit_count = objects.hit_count + EXCLUDED.hit_count,
646 updated_at_ms = EXCLUDED.updated_at_ms
647RETURNING id
648",
649 )
650 .bind(DRAFT_CHUNK_OBJECT_TYPE)
651 .bind(&chunk.id)
652 .bind(&chunk.sandbox_id)
653 .bind(&chunk.status)
654 .bind(dedup_key)
655 .bind(i64::from(chunk.hit_count))
656 .bind(payload)
657 .bind(chunk.first_seen_ms)
658 .bind(chunk.last_seen_ms)
659 .fetch_one(&self.pool)
660 .await
661 .map_err(|e| map_db_error(&e))?;
662 Ok(row.get::<String, _>("id"))
663 }
664
665 pub async fn get_draft_chunk(&self, id: &str) -> PersistenceResult<Option<DraftChunkRecord>> {
666 let row = sqlx::query(

Callers

nothing calls this directly

Calls 2

map_db_errorFunction · 0.85

Tested by

no test coverage detected