diff --git a/backend/parsers/windmill-parser-ts/src/asset_parser.rs b/backend/parsers/windmill-parser-ts/src/asset_parser.rs index 4a9868cc33..6ac4c4dd17 100644 --- a/backend/parsers/windmill-parser-ts/src/asset_parser.rs +++ b/backend/parsers/windmill-parser-ts/src/asset_parser.rs @@ -5,7 +5,8 @@ use swc_ecma_ast::{CallExpr, Expr, Lit, MemberExpr, MemberProp, Str}; use swc_ecma_parser::{lexer::Lexer, Parser, StringInput, Syntax, TsSyntax}; use swc_ecma_visit::{Visit, VisitWith}; use windmill_parser::asset_parser::{ - merge_assets, parse_asset_syntax, AssetKind, AssetUsageAccessType, ParseAssetsResult, + detect_sql_access_type, merge_assets, parse_asset_syntax, AssetKind, AssetUsageAccessType, + ParseAssetsResult, }; use AssetUsageAccessType::*; @@ -229,36 +230,3 @@ impl AssetsFinder { Ok(()) } } - -fn detect_sql_access_type(sql: &str) -> Option { - let first_kw = sql - .trim() - .split_whitespace() - .next() - .unwrap_or("") - .to_lowercase(); - - // Check for write operations - let has_write = first_kw.starts_with("insert") - || first_kw.starts_with("update") - || first_kw.starts_with("delete") - || first_kw.starts_with("drop") - || first_kw.starts_with("create") - || first_kw.starts_with("alter") - || first_kw.starts_with("truncate") - || first_kw.starts_with("merge"); - - // Check for read operations - let has_read = first_kw.starts_with("select") - || first_kw.starts_with("with") // CTEs, usually for reads - || first_kw.starts_with("show") - || first_kw.starts_with("describe") - || first_kw.starts_with("explain"); - - match (has_read, has_write) { - (true, true) => Some(RW), - (true, false) => Some(R), - (false, true) => Some(W), - (false, false) => None, // Unknown - couldn't determine - } -} diff --git a/backend/parsers/windmill-parser/src/asset_parser.rs b/backend/parsers/windmill-parser/src/asset_parser.rs index 6914f55f1f..26a9203c8e 100644 --- a/backend/parsers/windmill-parser/src/asset_parser.rs +++ b/backend/parsers/windmill-parser/src/asset_parser.rs @@ -73,3 +73,36 @@ pub fn parse_asset_syntax(s: &str) -> Option<(AssetKind, &str)> { None } } + +pub fn detect_sql_access_type(sql: &str) -> Option { + let first_kw = sql + .trim() + .split_whitespace() + .next() + .unwrap_or("") + .to_lowercase(); + + // Check for write operations + let has_write = first_kw.starts_with("insert") + || first_kw.starts_with("update") + || first_kw.starts_with("delete") + || first_kw.starts_with("drop") + || first_kw.starts_with("create") + || first_kw.starts_with("alter") + || first_kw.starts_with("truncate") + || first_kw.starts_with("merge"); + + // Check for read operations + let has_read = first_kw.starts_with("select") + || first_kw.starts_with("with") // CTEs, usually for reads + || first_kw.starts_with("show") + || first_kw.starts_with("describe") + || first_kw.starts_with("explain"); + + match (has_read, has_write) { + (true, true) => Some(RW), + (true, false) => Some(R), + (false, true) => Some(W), + (false, false) => None, // Unknown - couldn't determine + } +}