diff options
Diffstat (limited to 'lib')
| -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()) + } } |
