From 2e2dc9707c15ed46290849e7e9ec41f012a18d51 Mon Sep 17 00:00:00 2001 From: rtkay123 Date: Mon, 30 Mar 2026 00:05:31 +0200 Subject: feat(schema): update schema --- lib/api-config/src/schema/mod.rs | 50 +++++++++++++++++++++++++++++++++++----- 1 file changed, 44 insertions(+), 6 deletions(-) (limited to 'lib') 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 + Send + Sync, version: impl AsRef + Send + Sync, ) -> Result, ConfigurationError>; + + async fn update_schema( + &self, + kind: impl AsRef + Send + Sync, + version: impl AsRef + Send + Sync, + schema: &serde_json::Value, + ) -> Result; } #[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 + Send + Sync, + version: impl AsRef + Send + Sync, + schema: &serde_json::Value, + ) -> Result { + 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()) + } } -- cgit v1.2.3