diff options
| author | rtkay123 <dev@kanjala.com> | 2026-04-01 09:05:33 +0200 |
|---|---|---|
| committer | rtkay123 <dev@kanjala.com> | 2026-04-01 09:05:33 +0200 |
| commit | daeb5311840680599a0ce6e49d181b9289010f68 (patch) | |
| tree | d0c9c040ca003a6d431781b867c4290cbe5c9ef2 /lib/api-config/src/schema/implementation.rs | |
| parent | 2c336f0339747aa77a8fe6613b83200c8d4902a5 (diff) | |
| download | warden-daeb5311840680599a0ce6e49d181b9289010f68.tar.bz2 warden-daeb5311840680599a0ce6e49d181b9289010f68.zip | |
feat(schema): cursor pagination
Diffstat (limited to 'lib/api-config/src/schema/implementation.rs')
| -rw-r--r-- | lib/api-config/src/schema/implementation.rs | 42 |
1 files changed, 8 insertions, 34 deletions
diff --git a/lib/api-config/src/schema/implementation.rs b/lib/api-config/src/schema/implementation.rs index c414879..ca0757f 100644 --- a/lib/api-config/src/schema/implementation.rs +++ b/lib/api-config/src/schema/implementation.rs @@ -1,7 +1,10 @@ use async_trait::async_trait; use tracing::debug; +use warden_core::pagination::{Connection, PaginationArgs}; -use crate::schema::{self, SchemaDriver, SchemaService, TransactionSchema}; +use crate::schema::{ + self, SchemaDriver, SchemaService, TransactionSchema, pagination::DecodedSchemaPagination, +}; #[async_trait] impl SchemaDriver for SchemaService { @@ -44,41 +47,12 @@ impl SchemaDriver for SchemaService { } #[tracing::instrument(skip(self))] - async fn get_schemas( + async fn list_schemas( &self, + input: &PaginationArgs, limit: i64, - first: Option<i64>, - after: Option<&str>, - ) -> Result<Vec<TransactionSchema>, crate::ConfigurationError> { + ) -> Result<Connection<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) + schema::list_schemas::list_schemas(self, input, limit).await } } |
