From a42dd7d9774a57becffb717e533ffbce8312a6fd Mon Sep 17 00:00:00 2001 From: Michael Cuffaro Date: Sat, 30 Sep 2023 16:07:04 -0400 Subject: [PATCH] avoid more nulls --- src/lib.rs | 38 ++++++++++++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 4 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index b06fd7b0..8b2ba95c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2312,6 +2312,19 @@ fn get_conflict_columns(global_config: &SerdeMap, table_name: &str) -> Vec>(); + let trees = global_config .get("constraints") .and_then(|c| c.as_object()) @@ -2325,7 +2338,20 @@ fn get_conflict_columns(global_config: &SerdeMap, table_name: &str) -> Vec>(); - for key_columns in vec![primaries, uniques, &trees] { + let unders = global_config + .get("constraints") + .and_then(|c| c.as_object()) + .and_then(|o| o.get("under")) + .and_then(|t| t.as_object()) + .and_then(|o| o.get(table_name)) + .and_then(|t| t.as_array()) + .unwrap() + .iter() + .map(|v| v.as_object().unwrap()) + .map(|v| v.get("tcolumn").unwrap().clone()) + .collect::>(); + + for key_columns in vec![primaries, uniques, &foreigns, &trees, &unders] { for column in key_columns { if !conflict_columns.contains(column) { conflict_columns.push(column.clone()); @@ -2517,7 +2543,9 @@ pub async fn insert_new_row_tx( .and_then(|l| l.as_str()) .ok_or(SqlxCErr(format!("No 'rule' in {:?}", cell).into()))?; if level == "error" && causes_db_error(&rule) { - insert_null = true; + if !use_conflict_table || rule.starts_with("datatype:") { + insert_null = true; + } } messages.push(json!({ "column": column, @@ -3973,8 +4001,10 @@ async fn make_inserts( let level = cell_message.get("level").and_then(|l| l.as_str()).unwrap(); let rule = cell_message.get("rule").and_then(|l| l.as_str()).unwrap(); if level == "error" && causes_db_error(&rule) { - insert_null = true; - break; + if !table_name.ends_with("_conflict") || rule.starts_with("datatype:") { + insert_null = true; + break; + } } } }