(
&self,
object_type: &str,
id: &str,
name: &str,
scope: &str,
payload: &[u8],
labels: Option<&str>,
)
| 242 | } |
| 243 | |
| 244 | pub async fn put_scoped( |
| 245 | &self, |
| 246 | object_type: &str, |
| 247 | id: &str, |
| 248 | name: &str, |
| 249 | scope: &str, |
| 250 | payload: &[u8], |
| 251 | labels: Option<&str>, |
| 252 | ) -> PersistenceResult<()> { |
| 253 | let now_ms = current_time_ms(); |
| 254 | let labels_jsonb: Option<serde_json::Value> = labels |
| 255 | .map(serde_json::from_str) |
| 256 | .transpose() |
| 257 | .map_err(|e| PersistenceError::Encode(format!("invalid labels JSON: {e}")))?; |
| 258 | |
| 259 | sqlx::query( |
| 260 | r" |
| 261 | INSERT INTO objects (object_type, id, name, scope, payload, created_at_ms, updated_at_ms, labels, resource_version) |
| 262 | VALUES ($1, $2, $3, $4, $5, $6, $6, COALESCE($7, '{}'::jsonb), 1) |
| 263 | ON CONFLICT (object_type, name) WHERE name IS NOT NULL DO UPDATE SET |
| 264 | scope = EXCLUDED.scope, |
| 265 | payload = EXCLUDED.payload, |
| 266 | updated_at_ms = EXCLUDED.updated_at_ms, |
| 267 | labels = EXCLUDED.labels, |
| 268 | resource_version = objects.resource_version + 1 |
| 269 | ", |
| 270 | ) |
| 271 | .bind(object_type) |
| 272 | .bind(id) |
| 273 | .bind(name) |
| 274 | .bind(scope) |
| 275 | .bind(payload) |
| 276 | .bind(now_ms) |
| 277 | .bind(labels_jsonb) |
| 278 | .execute(&self.pool) |
| 279 | .await |
| 280 | .map_err(|e| map_db_error(&e))?; |
| 281 | Ok(()) |
| 282 | } |
| 283 | |
| 284 | pub async fn get( |
| 285 | &self, |
nothing calls this directly
no test coverage detected