Skip to content

Commit

Permalink
Merge branch 'main' into delete-row
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesaoverton committed Jul 24, 2023
2 parents a2e7aca + 32359b3 commit 9b73ffb
Showing 1 changed file with 36 additions and 31 deletions.
67 changes: 36 additions & 31 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -697,10 +697,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(),
};

Expand Down Expand Up @@ -930,6 +935,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<String> {
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 {
Expand Down Expand Up @@ -2561,36 +2596,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.
pub fn get_sql_type_from_global_config(
global_config: &SerdeMap,
table: &str,
column: &str,
pool: &AnyPool,
) -> Option<String> {
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 {
Expand Down

0 comments on commit 9b73ffb

Please sign in to comment.