From de42bb48aad07a574bd3ca43f5603beb9b3c4ea2 Mon Sep 17 00:00:00 2001 From: filipriec Date: Sun, 13 Jul 2025 08:51:47 +0200 Subject: [PATCH] deprecated function removed, no need for backup --- server/src/steel/server/execution.rs | 34 +------------------ .../tables_data/handlers/post_table_data.rs | 6 +++- .../tables_data/handlers/put_table_data.rs | 13 +++++-- .../post_table_data_steel_decimal_test.rs | 9 +++-- 4 files changed, 24 insertions(+), 38 deletions(-) diff --git a/server/src/steel/server/execution.rs b/server/src/steel/server/execution.rs index f0a398b..25bae3e 100644 --- a/server/src/steel/server/execution.rs +++ b/server/src/steel/server/execution.rs @@ -49,7 +49,7 @@ pub async fn create_steel_context_with_boolean_conversion( } /// Execute script with proper boolean handling -pub async fn execute_script_with_boolean_support( +pub async fn execute_script( script: String, target_type: &str, db_pool: Arc, @@ -92,38 +92,6 @@ pub async fn execute_script_with_boolean_support( } } -/// Original execute_script function (kept for backward compatibility) -/// Note: This doesn't include boolean conversion - use execute_script_with_boolean_support for new code -pub fn execute_script( - script: String, - target_type: &str, - db_pool: Arc, - context: SteelContext, -) -> Result { - let mut vm = Engine::new(); - let context = Arc::new(context); - - // Register existing Steel functions - register_steel_functions(&mut vm, context.clone()); - - // Register all decimal math functions using the steel_decimal crate - register_decimal_math_functions(&mut vm); - - // IMPORTANT: Register variables from the context with the Steel VM - // This makes the get-var function available with the actual variable values - FunctionRegistry::register_variables(&mut vm, context.row_data.clone()); - - // Execute script and process results - let results = vm.compile_and_run_raw_program(script) - .map_err(|e| ExecutionError::RuntimeError(e.to_string()))?; - - // Convert results to target type - match target_type { - "STRINGS" => process_string_results(results), - _ => Err(ExecutionError::UnsupportedType(target_type.into())) - } -} - fn register_steel_functions(vm: &mut Engine, context: Arc) { // Register steel_get_column with row context vm.register_fn("steel_get_column", { diff --git a/server/src/tables_data/handlers/post_table_data.rs b/server/src/tables_data/handlers/post_table_data.rs index 46737c0..835abde 100644 --- a/server/src/tables_data/handlers/post_table_data.rs +++ b/server/src/tables_data/handlers/post_table_data.rs @@ -136,8 +136,12 @@ pub async fn post_table_data( script_record.script, "STRINGS", Arc::new(db_pool.clone()), - context, + schema_id, + profile_name.clone(), + table_name.clone(), + string_data_for_scripts.clone(), ) + .await .map_err(|e| Status::invalid_argument( format!("Script execution failed for '{}': {}", target_column, e) ))?; diff --git a/server/src/tables_data/handlers/put_table_data.rs b/server/src/tables_data/handlers/put_table_data.rs index 2df98be..0c487ab 100644 --- a/server/src/tables_data/handlers/put_table_data.rs +++ b/server/src/tables_data/handlers/put_table_data.rs @@ -199,8 +199,17 @@ pub async fn put_table_data( db_pool: Arc::new(db_pool.clone()), }; - let script_result = execution::execute_script(script_record.script, "STRINGS", Arc::new(db_pool.clone()), context) - .map_err(|e| Status::invalid_argument(format!("Script execution failed for '{}': {}", target_column, e)))?; + let script_result = execution::execute_script( + script_record.script, + "STRINGS", + Arc::new(db_pool.clone()), + schema_id, + profile_name.clone(), + table_name.clone(), + final_context_data.clone(), + ) + .await + .map_err(|e| Status::invalid_argument(format!("Script execution failed for '{}': {}", target_column, e)))?; let Value::Strings(mut script_output_vec) = script_result else { return Err(Status::internal("Script must return string values")); diff --git a/server/tests/tables_data/post/post_table_data_steel_decimal_test.rs b/server/tests/tables_data/post/post_table_data_steel_decimal_test.rs index 36c31a8..dd9a12c 100644 --- a/server/tests/tables_data/post/post_table_data_steel_decimal_test.rs +++ b/server/tests/tables_data/post/post_table_data_steel_decimal_test.rs @@ -39,8 +39,13 @@ async fn discover_steel_decimal_output( script.to_string(), "STRINGS", Arc::new(pool.clone()), - context, - ).map_err(|e| format!("Script execution failed: {}", e))?; + 1, + "test_schema".to_string(), + "test_table".to_string(), + input_data, + ) + .await + .map_err(|e| format!("Script execution failed: {}", e))?; let Value::Strings(mut script_output) = script_result else { return Err("Script must return string values".to_string());