From 0235e1a584e701b9ff2ce89d38a0d2a8d8bca47b Mon Sep 17 00:00:00 2001 From: sharkAndshark Date: Mon, 18 Sep 2023 11:14:04 +0800 Subject: [PATCH] Add clip_geom,buffer under auto_publish conf --- martin/src/pg/config.rs | 6 ++++++ martin/src/pg/configurator.rs | 15 ++++++++++++++- martin/src/pg/table_source.rs | 10 +++++++--- 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/martin/src/pg/config.rs b/martin/src/pg/config.rs index 85df68e91..ee5ea0db1 100644 --- a/martin/src/pg/config.rs +++ b/martin/src/pg/config.rs @@ -82,6 +82,12 @@ pub struct PgCfgPublishType { #[serde(skip_serializing_if = "Option::is_none")] #[serde(alias = "id_column")] pub id_columns: Option>, + + #[serde(skip_serializing_if = "Option::is_none")] + pub clip_geom: Option, + + #[serde(skip_serializing_if = "Option::is_none")] + pub buffer: Option, } impl PgConfig { diff --git a/martin/src/pg/configurator.rs b/martin/src/pg/configurator.rs index f4290a54a..5a1471d36 100755 --- a/martin/src/pg/configurator.rs +++ b/martin/src/pg/configurator.rs @@ -28,6 +28,8 @@ pub struct PgBuilderAuto { source_id_format: String, schemas: Option>, id_columns: Option>, + clip_geom: Option, + buffer: Option, } #[derive(Debug)] @@ -63,7 +65,12 @@ impl PgBuilder { // FIXME: this function has gotten too long due to the new formatting rules, need to be refactored #[allow(clippy::too_many_lines)] pub async fn instantiate_tables(&self) -> Result<(Sources, TableInfoSources)> { - let mut db_tables_info = query_available_tables(&self.pool).await?; + let (clip_geom, buffer) = if let Some(auto_tables) = &self.auto_tables { + (auto_tables.clip_geom, auto_tables.buffer) + } else { + (None, None) + }; + let mut db_tables_info = query_available_tables(&self.pool, clip_geom, buffer).await?; // Match configured sources with the discovered ones and add them to the pending list. let mut used = HashSet::<(&str, &str, &str)>::new(); @@ -317,6 +324,8 @@ fn new_auto_publish(config: &PgConfig, is_function: bool) -> Option Option default(merge_opt_hs(&a.from_schemas, &None)), BoolOrObject::Bool(false) => None, @@ -420,6 +431,8 @@ mod tests { source_id_format: source_id_format.to_string(), schemas: schemas.map(|s| s.iter().map(|s| (*s).to_string()).collect()), id_columns: None, + clip_geom: None, + buffer: None, }) } diff --git a/martin/src/pg/table_source.rs b/martin/src/pg/table_source.rs index 38fb11618..757712590 100644 --- a/martin/src/pg/table_source.rs +++ b/martin/src/pg/table_source.rs @@ -19,7 +19,11 @@ static DEFAULT_EXTENT: u32 = 4096; static DEFAULT_BUFFER: u32 = 64; static DEFAULT_CLIP_GEOM: bool = true; -pub async fn query_available_tables(pool: &PgPool) -> Result { +pub async fn query_available_tables( + pool: &PgPool, + clip_geom: Option, + buffer: Option, +) -> Result { let conn = pool.get().await?; let rows = conn .query(include_str!("scripts/query_available_tables.sql"), &[]) @@ -55,8 +59,8 @@ pub async fn query_available_tables(pool: &PgPool) -> Result