From a2acd1732ecdd9ded7ce5fade91518119790e9a6 Mon Sep 17 00:00:00 2001 From: Yuri Astrakhan Date: Thu, 3 Aug 2023 01:56:35 -0400 Subject: [PATCH] Minor internal cleanup --- martin/src/pg/configurator.rs | 25 ++++++++++++------------- martin/src/pg/utils.rs | 4 ++++ 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/martin/src/pg/configurator.rs b/martin/src/pg/configurator.rs index 8eebe4187..69b3c3bcd 100755 --- a/martin/src/pg/configurator.rs +++ b/martin/src/pg/configurator.rs @@ -24,22 +24,21 @@ pub type SqlFuncInfoMapMap = InfoMap>; pub type SqlTableInfoMapMapMap = InfoMap>>; #[derive(Debug, PartialEq)] -pub struct PgBuilderPublish { +pub struct PgBuilderAuto { source_id_format: String, schemas: Option>, } -impl PgBuilderPublish { +impl PgBuilderAuto { pub fn new( is_function: bool, source_id_format: Option<&String>, schemas: Option>, ) -> Self { - let source_id_format = source_id_format - .cloned() - .unwrap_or_else(|| (if is_function { "{function}" } else { "{table}" }).to_string()); Self { - source_id_format, + source_id_format: source_id_format.cloned().unwrap_or_else(|| { + (if is_function { "{function}" } else { "{table}" }).to_string() + }), schemas, } } @@ -51,8 +50,8 @@ pub struct PgBuilder { default_srid: Option, disable_bounds: bool, max_feature_count: Option, - auto_functions: Option, - auto_tables: Option, + auto_functions: Option, + auto_tables: Option, id_resolver: IdResolver, tables: TableInfoSources, functions: FuncInfoSources, @@ -237,14 +236,14 @@ impl PgBuilder { } } -fn new_auto_publish(config: &PgConfig, is_function: bool) -> Option { - let default = |schemas| Some(PgBuilderPublish::new(is_function, None, schemas)); +fn new_auto_publish(config: &PgConfig, is_function: bool) -> Option { + let default = |schemas| Some(PgBuilderAuto::new(is_function, None, schemas)); if let Some(bo_a) = &config.auto_publish { match bo_a { BoolOrObject::Object(a) => match if is_function { &a.functions } else { &a.tables } { Some(bo_i) => match bo_i { - BoolOrObject::Object(item) => Some(PgBuilderPublish::new( + BoolOrObject::Object(item) => Some(PgBuilderAuto::new( is_function, item.source_id_format.as_ref(), merge_opt_hs(&a.from_schemas, &item.from_schemas), @@ -323,8 +322,8 @@ mod tests { use super::*; #[allow(clippy::unnecessary_wraps)] - fn builder(source_id_format: &str, schemas: Option<&[&str]>) -> Option { - Some(PgBuilderPublish { + fn builder(source_id_format: &str, schemas: Option<&[&str]>) -> Option { + Some(PgBuilderAuto { source_id_format: source_id_format.to_string(), schemas: schemas.map(|s| s.iter().map(|s| (*s).to_string()).collect()), }) diff --git a/martin/src/pg/utils.rs b/martin/src/pg/utils.rs index 4b80cd62a..fc85f2917 100755 --- a/martin/src/pg/utils.rs +++ b/martin/src/pg/utils.rs @@ -91,6 +91,10 @@ fn find_info_kv<'a, T>( } } +/// Find a key in a map, ignoring case. +/// If there is no exact match, but there is a case-insensitive match, return that as `Ok(Some(value))`. +/// If there is no exact match and there are multiple case-insensitive matches, return an error with a vector of the possible matches. +/// If there is no match, return `Ok(None)`. pub fn find_kv_ignore_case<'a, T>( map: &'a InfoMap, key: &str,