From 747a594a8010d6ba5dc97a583335aba2fb35392a Mon Sep 17 00:00:00 2001 From: rtkay123 Date: Sun, 29 Mar 2026 21:12:32 +0200 Subject: feat(schema): get schema --- lib/api-config/src/schema/mod.rs | 42 ++++++++++++++++++++++++++++++++++------ 1 file changed, 36 insertions(+), 6 deletions(-) (limited to 'lib/api-config') diff --git a/lib/api-config/src/schema/mod.rs b/lib/api-config/src/schema/mod.rs index 4e68129..33d7922 100644 --- a/lib/api-config/src/schema/mod.rs +++ b/lib/api-config/src/schema/mod.rs @@ -40,6 +40,12 @@ pub trait SchemaDriver { kind: impl AsRef + Send + Sync, version: impl AsRef + Send + Sync, ) -> Result<(), ConfigurationError>; + + async fn get_schema( + &self, + kind: impl AsRef + Send + Sync, + version: impl AsRef + Send + Sync, + ) -> Result, ConfigurationError>; } #[async_trait] @@ -54,11 +60,11 @@ impl SchemaDriver for AppState { TransactionSchema, "insert into transaction_schema (type, version, json_schema) values ($1, $2, $3) returning - type as kind, - version, - json_schema as schema, - created_at, - updated_at + type as kind, + version, + json_schema as schema, + created_at, + updated_at ", kind.as_ref(), version.as_ref(), @@ -74,7 +80,8 @@ impl SchemaDriver for AppState { kind: impl AsRef + Send + Sync, version: impl AsRef + Send + Sync, ) -> Result<(), crate::ConfigurationError> { - sqlx::query!("delete from transaction_schema where type = $1 and version = $2", + sqlx::query!( + "delete from transaction_schema where type = $1 and version = $2", kind.as_ref(), version.as_ref(), ) @@ -82,4 +89,27 @@ impl SchemaDriver for AppState { .await?; Ok(()) } + + async fn get_schema( + &self, + kind: impl AsRef + Send + Sync, + version: impl AsRef + Send + Sync, + ) -> Result, crate::ConfigurationError> { + 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", + kind.as_ref(), + version.as_ref(), + ) + .fetch_optional(&self.database) + .await?; + + Ok(result) + } } -- cgit v1.2.3