aboutsummaryrefslogtreecommitdiffstats
path: root/lib/api-config/src/schema/implementation.rs
diff options
context:
space:
mode:
authorrtkay123 <dev@kanjala.com>2026-03-31 21:35:49 +0200
committerrtkay123 <dev@kanjala.com>2026-03-31 21:35:49 +0200
commit2c336f0339747aa77a8fe6613b83200c8d4902a5 (patch)
tree5e77ac42c48c455fd9869df6baf39c0887f6d8e6 /lib/api-config/src/schema/implementation.rs
parentcec58d78e968250e4c589899eab460d1132f6d01 (diff)
downloadwarden-2c336f0339747aa77a8fe6613b83200c8d4902a5.tar.bz2
warden-2c336f0339747aa77a8fe6613b83200c8d4902a5.zip
test(config): schema
Diffstat (limited to 'lib/api-config/src/schema/implementation.rs')
-rw-r--r--lib/api-config/src/schema/implementation.rs84
1 files changed, 84 insertions, 0 deletions
diff --git a/lib/api-config/src/schema/implementation.rs b/lib/api-config/src/schema/implementation.rs
new file mode 100644
index 0000000..c414879
--- /dev/null
+++ b/lib/api-config/src/schema/implementation.rs
@@ -0,0 +1,84 @@
+use async_trait::async_trait;
+use tracing::debug;
+
+use crate::schema::{self, SchemaDriver, SchemaService, TransactionSchema};
+
+#[async_trait]
+impl SchemaDriver for SchemaService {
+ #[tracing::instrument(skip(self, schema))]
+ async fn create_schema(
+ &self,
+ kind: &str,
+ version: &str,
+ schema: &serde_json::Value,
+ ) -> Result<TransactionSchema, crate::ConfigurationError> {
+ schema::create_schema::create_schema(self, kind, version, schema).await
+ }
+
+ #[tracing::instrument(skip(self))]
+ async fn delete_schema(
+ &self,
+ kind: &str,
+ version: &str,
+ ) -> Result<(), crate::ConfigurationError> {
+ schema::delete_schema::delete_schema(self, kind, version).await
+ }
+
+ #[tracing::instrument(skip(self))]
+ async fn get_schema(
+ &self,
+ kind: &str,
+ version: &str,
+ ) -> Result<Option<TransactionSchema>, crate::ConfigurationError> {
+ schema::get_schema::get_schema(self, kind, version).await
+ }
+
+ #[tracing::instrument(skip(self, schema))]
+ async fn update_schema(
+ &self,
+ kind: &str,
+ version: &str,
+ schema: &serde_json::Value,
+ ) -> Result<Option<TransactionSchema>, crate::ConfigurationError> {
+ schema::update_schema::update_schema(self, kind, version, schema).await
+ }
+
+ #[tracing::instrument(skip(self))]
+ async fn get_schemas(
+ &self,
+ limit: i64,
+ first: Option<i64>,
+ after: Option<&str>,
+ ) -> Result<Vec<TransactionSchema>, crate::ConfigurationError> {
+ debug!("getting transaction schemas");
+ let limit = first.unwrap_or(limit);
+ let mut last_type = String::default();
+ let mut last_version = String::default();
+
+ if let Some(s) = after {
+ let parts: Vec<&str> = s.split(',').collect();
+ if parts.len() == 2 {
+ last_type = parts[0].to_string();
+ last_version = parts[1].to_string();
+ }
+ }
+
+ let rows = sqlx::query_as!(
+ TransactionSchema,
+ "
+ select *
+ from transaction_schema
+ where ($1 = '' or (schema_type, schema_version) > ($1, $2))
+ order by schema_type asc, schema_version asc
+ limit $3
+ ",
+ &last_type,
+ &last_version,
+ limit + 1
+ )
+ .fetch_all(&self.database)
+ .await?;
+
+ Ok(rows)
+ }
+}