From a8273a5210fda3ed9e09273182323e451a4725d8 Mon Sep 17 00:00:00 2001 From: Michael Cuffaro Date: Thu, 22 Jun 2023 13:42:29 -0400 Subject: [PATCH 1/2] make get_sql_type_from_global_config() public --- src/lib.rs | 60 +++++++++++++++++++++++++++--------------------------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index c28818e1..49d62f85 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -926,6 +926,36 @@ pub async fn configure_db( return Ok((sorted_tables, constraints_config)); } +/// Given the global config map, a table name, a column name, and a database connection pool +/// used to determine the database type return the column's SQL type. +pub fn get_sql_type_from_global_config( + global_config: &SerdeMap, + table: &str, + column: &str, + pool: &AnyPool, +) -> Option { + let dt_config = global_config + .get("datatype") + .and_then(|d| d.as_object()) + .unwrap(); + let normal_table_name; + if let Some(s) = table.strip_suffix("_conflict") { + normal_table_name = String::from(s); + } else { + normal_table_name = table.to_string(); + } + let dt = global_config + .get("table") + .and_then(|t| t.get(normal_table_name)) + .and_then(|t| t.get("column")) + .and_then(|c| c.get(column)) + .and_then(|c| c.get("datatype")) + .and_then(|d| d.as_str()) + .and_then(|d| Some(d.to_string())) + .unwrap(); + get_sql_type(&dt_config, &dt, pool) +} + /// Various VALVE commands, used with [valve()](valve). #[derive(Debug, PartialEq, Eq)] pub enum ValveCommand { @@ -1578,36 +1608,6 @@ fn get_sql_type(dt_config: &SerdeMap, datatype: &String, pool: &AnyPool) -> Opti return get_sql_type(dt_config, &parent_datatype.to_string(), pool); } -/// Given the global config map, a table name, a column name, and a database connection pool -/// used to determine the database type return the column's SQL type. -fn get_sql_type_from_global_config( - global_config: &SerdeMap, - table: &str, - column: &str, - pool: &AnyPool, -) -> Option { - let dt_config = global_config - .get("datatype") - .and_then(|d| d.as_object()) - .unwrap(); - let normal_table_name; - if let Some(s) = table.strip_suffix("_conflict") { - normal_table_name = String::from(s); - } else { - normal_table_name = table.to_string(); - } - let dt = global_config - .get("table") - .and_then(|t| t.get(normal_table_name)) - .and_then(|t| t.get("column")) - .and_then(|c| c.get(column)) - .and_then(|c| c.get("datatype")) - .and_then(|d| d.as_str()) - .and_then(|d| Some(d.to_string())) - .unwrap(); - get_sql_type(&dt_config, &dt, pool) -} - /// Given a SQL type, return the appropriate CAST(...) statement for casting the SQL_PARAM /// from a TEXT column. fn cast_sql_param_from_text(sql_type: &str) -> String { From 96598f9d18bd088eea51a9232e54d57cd90f0ce2 Mon Sep 17 00:00:00 2001 From: "James A. Overton" Date: Fri, 23 Jun 2023 15:40:20 +0000 Subject: [PATCH 2/2] Don't panic on failure to canonicalize --- src/lib.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 49d62f85..7e584524 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -693,10 +693,15 @@ pub async fn configure_db( // If an entry of the tables_config has no path then it is an internal table which need // not be configured explicitly. Currently the only example is the message table. None => continue, - Some(p) if !Path::new(p).canonicalize()?.is_file() => { + Some(p) if !Path::new(p).is_file() => { eprintln!("WARN: File does not exist {}", p); continue; } + Some(p) if Path::new(p).canonicalize().is_err() => { + eprintln!("WARN: File path could not be made canonical {}", p); + continue; + } + Some(p) => path = p.to_string(), };