(
&self,
object_type: &str,
id: &str,
name: &str,
payload: &[u8],
labels: Option<&str>,
)
| 55 | } |
| 56 | |
| 57 | pub async fn put( |
| 58 | &self, |
| 59 | object_type: &str, |
| 60 | id: &str, |
| 61 | name: &str, |
| 62 | payload: &[u8], |
| 63 | labels: Option<&str>, |
| 64 | ) -> PersistenceResult<()> { |
| 65 | let now_ms = current_time_ms(); |
| 66 | let labels_jsonb: Option<serde_json::Value> = labels |
| 67 | .map(serde_json::from_str) |
| 68 | .transpose() |
| 69 | .map_err(|e| PersistenceError::Encode(format!("invalid labels JSON: {e}")))?; |
| 70 | |
| 71 | sqlx::query( |
| 72 | r" |
| 73 | INSERT INTO objects (object_type, id, name, payload, created_at_ms, updated_at_ms, labels) |
| 74 | VALUES ($1, $2, $3, $4, $5, $5, COALESCE($6, '{}'::jsonb)) |
| 75 | ON CONFLICT (object_type, name) WHERE name IS NOT NULL DO UPDATE SET |
| 76 | payload = EXCLUDED.payload, |
| 77 | updated_at_ms = EXCLUDED.updated_at_ms, |
| 78 | labels = EXCLUDED.labels |
| 79 | ", |
| 80 | ) |
| 81 | .bind(object_type) |
| 82 | .bind(id) |
| 83 | .bind(name) |
| 84 | .bind(payload) |
| 85 | .bind(now_ms) |
| 86 | .bind(labels_jsonb) |
| 87 | .execute(&self.pool) |
| 88 | .await |
| 89 | .map_err(|e| map_db_error(&e))?; |
| 90 | Ok(()) |
| 91 | } |
| 92 | |
| 93 | pub async fn put_if( |
| 94 | &self, |
nothing calls this directly
no test coverage detected