aboutsummaryrefslogtreecommitdiffstats
path: root/lib/api-config/src
diff options
context:
space:
mode:
Diffstat (limited to 'lib/api-config/src')
-rw-r--r--lib/api-config/src/schema/mod.rs42
1 files changed, 36 insertions, 6 deletions
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<str> + Send + Sync,
version: impl AsRef<str> + Send + Sync,
) -> Result<(), ConfigurationError>;
+
+ async fn get_schema(
+ &self,
+ kind: impl AsRef<str> + Send + Sync,
+ version: impl AsRef<str> + Send + Sync,
+ ) -> Result<Option<TransactionSchema>, 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<str> + Send + Sync,
version: impl AsRef<str> + 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<str> + Send + Sync,
+ version: impl AsRef<str> + Send + Sync,
+ ) -> Result<Option<TransactionSchema>, 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)
+ }
}