diff options
| author | rtkay123 <dev@kanjala.com> | 2026-03-30 00:05:31 +0200 |
|---|---|---|
| committer | rtkay123 <dev@kanjala.com> | 2026-03-30 00:05:31 +0200 |
| commit | 2e2dc9707c15ed46290849e7e9ec41f012a18d51 (patch) | |
| tree | dba84157da3b7fb6d9e6a5af1df0911b3b11452b /lib/api-config | |
| parent | 747a594a8010d6ba5dc97a583335aba2fb35392a (diff) | |
| download | warden-2e2dc9707c15ed46290849e7e9ec41f012a18d51.tar.bz2 warden-2e2dc9707c15ed46290849e7e9ec41f012a18d51.zip | |
feat(schema): update schema
Diffstat (limited to 'lib/api-config')
| -rw-r--r-- | lib/api-config/src/schema/mod.rs | 50 |
1 files changed, 44 insertions, 6 deletions
diff --git a/lib/api-config/src/schema/mod.rs b/lib/api-config/src/schema/mod.rs index 33d7922..1fdbcef 100644 --- a/lib/api-config/src/schema/mod.rs +++ b/lib/api-config/src/schema/mod.rs @@ -46,6 +46,13 @@ pub trait SchemaDriver { kind: impl AsRef<str> + Send + Sync, version: impl AsRef<str> + Send + Sync, ) -> Result<Option<TransactionSchema>, ConfigurationError>; + + async fn update_schema( + &self, + kind: impl AsRef<str> + Send + Sync, + version: impl AsRef<str> + Send + Sync, + schema: &serde_json::Value, + ) -> Result<TransactionSchema, ConfigurationError>; } #[async_trait] @@ -98,12 +105,12 @@ impl SchemaDriver for AppState { let result = sqlx::query_as!( TransactionSchema, "select - type as kind, - version, - json_schema as schema, - created_at, - updated_at - from transaction_schema where type = $1 and version = $2", + type as kind, + version, + json_schema as schema, + created_at, + updated_at + from transaction_schema where type = $1 and version = $2", kind.as_ref(), version.as_ref(), ) @@ -112,4 +119,35 @@ impl SchemaDriver for AppState { Ok(result) } + + async fn update_schema( + &self, + kind: impl AsRef<str> + Send + Sync, + version: impl AsRef<str> + Send + Sync, + schema: &serde_json::Value, + ) -> Result<TransactionSchema, crate::ConfigurationError> { + sqlx::query_as!(TransactionSchema, + " + update + transaction_schema + set + json_schema = $3 + where + type = $1 + and version = $2 + returning + type as kind, + version, + json_schema as schema, + created_at, + updated_at + ", + kind.as_ref(), + version.as_ref(), + sqlx::types::Json(&schema) as _ + ) + .fetch_one(&self.database) + .await + .map_err(|e| e.into()) + } } |
