| 537 | } |
| 538 | |
| 539 | pub async fn get_policy_by_version( |
| 540 | &self, |
| 541 | sandbox_id: &str, |
| 542 | version: i64, |
| 543 | ) -> PersistenceResult<Option<PolicyRecord>> { |
| 544 | let row = sqlx::query( |
| 545 | r#" |
| 546 | SELECT "id", "scope", "version", "status", "payload", "created_at_ms" |
| 547 | FROM "objects" |
| 548 | WHERE "object_type" = ?1 AND "scope" = ?2 AND "version" = ?3 |
| 549 | "#, |
| 550 | ) |
| 551 | .bind(POLICY_OBJECT_TYPE) |
| 552 | .bind(sandbox_id) |
| 553 | .bind(version) |
| 554 | .fetch_optional(&self.pool) |
| 555 | .await |
| 556 | .map_err(|e| map_db_error(&e))?; |
| 557 | |
| 558 | row.map(row_to_policy_record).transpose() |
| 559 | } |
| 560 | |
| 561 | pub async fn list_policies( |
| 562 | &self, |