this miracle compiled, idk if it even does what i want but should run custom sql queries from steel script. Da heck if this works, my gosh

This commit is contained in:
filipriec
2025-03-12 23:39:10 +01:00
parent 22564682c8
commit ec323d24be
7 changed files with 150 additions and 5 deletions

View File

@@ -3,6 +3,7 @@ use tonic::Status;
use sqlx::{PgPool, Error as SqlxError};
use common::proto::multieko2::table_script::{PostTableScriptRequest, TableScriptResponse};
use serde_json::Value;
use crate::steel::server::syntax_parser::SyntaxParser;
const SYSTEM_COLUMNS: &[&str] = &["id", "deleted", "created_at"];
@@ -61,20 +62,29 @@ pub async fn post_table_script(
)
.map_err(|e| Status::invalid_argument(e))?;
// Parse and transform the script
let parser = SyntaxParser::new();
let parsed_script = parser.parse(&request.script);
// Extract dependencies
let (source_tables, source_columns) = parser.extract_dependencies(&request.script);
// Store script in database with column type and profile_id
let script_record = sqlx::query!(
r#"INSERT INTO table_scripts
(table_definitions_id, target_column, target_column_type, script, description, profile_id)
VALUES ($1, $2, $3, $4, $5, $6)
(table_definitions_id, target_column, target_column_type,
script, source_tables, source_columns, description, profile_id)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8)
RETURNING id"#,
request.table_definition_id,
request.target_column,
column_type,
request.script,
parsed_script, // Store transformed script
&Vec::from_iter(source_tables),
&Vec::from_iter(source_columns),
request.description,
table_def.profile_id // Use the profile_id from table_definitions
)
table_def.profile_id
)
.fetch_one(db_pool)
.await
.map_err(|e| match e {