From 67dad03c6c291665dca3dd38553bae463ccf61ed Mon Sep 17 00:00:00 2001 From: Jason Shin Date: Thu, 4 Apr 2024 23:35:46 +1100 Subject: [PATCH] fix: fixed quote style param bug (#100) * fix: fixed quote style param bug * test: add some quoted fields in insert tests * test: revert mysql test as it does not support quoted fields --- src/ts_generator/sql_parser/translate_insert.rs | 4 ++-- tests/postgres_insert_query_parameters.rs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/ts_generator/sql_parser/translate_insert.rs b/src/ts_generator/sql_parser/translate_insert.rs index 8a393bf9..c29faa78 100644 --- a/src/ts_generator/sql_parser/translate_insert.rs +++ b/src/ts_generator/sql_parser/translate_insert.rs @@ -34,12 +34,12 @@ pub async fn translate_insert( let placeholder = get_expr_placeholder(value); if placeholder.is_some() { - let match_col = columns + let match_col = &columns .get(column) .unwrap_or_else(|| { panic!("Matching column of idx {column} is not found while processing insert params") }) - .to_string(); + .value; let field = table_details.get(match_col.as_str()).unwrap_or_else(|| { panic!("Column {match_col} is not found while processing insert params") diff --git a/tests/postgres_insert_query_parameters.rs b/tests/postgres_insert_query_parameters.rs index f49a7ee9..ed2e2bad 100644 --- a/tests/postgres_insert_query_parameters.rs +++ b/tests/postgres_insert_query_parameters.rs @@ -17,7 +17,7 @@ run_test!(should_pick_query_params_from_single_row_of_values, TestConfig::new("p //// TS query //// r#" const someInputQuery = sql` -INSERT INTO items (id, food_type, time_takes_to_cook, table_id, points) +INSERT INTO items (id, "food_type", time_takes_to_cook, table_id, points) VALUES ($2, $1, 2, $3, 2); ` @@ -43,7 +43,7 @@ run_test!(should_pick_query_params_from_multiple_rows_of_values, TestConfig::new //// TS query //// r#" const someInputQuery = sql` -INSERT INTO items (id, food_type, time_takes_to_cook, table_id, points) +INSERT INTO items (id, "food_type", time_takes_to_cook, table_id, points) VALUES ($2, $1, 2, $3, 2), ($5, 'test', $4, $7, $6);