From 3b8a2549e9eae684fc70769ab9014a4069cb1c69 Mon Sep 17 00:00:00 2001 From: Ophir Lojkine Date: Fri, 23 Oct 2026 00:31:04 +0000 Subject: [PATCH] Decouple SQL file parsing from database connections --- src/webserver/database/sql.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/webserver/database/sql.rs b/src/webserver/database/sql.rs index 02f4c28d..81f82906 100644 --- a/src/webserver/database/sql.rs +++ b/src/webserver/database/sql.rs @@ -51,13 +51,19 @@ pub(super) use statement::{OutputColumn, SourceLocation}; impl SqlFile { #[must_use] pub fn new(db: &Database, sql: &str, source_path: &Path) -> Self { - let dialect = dialect::parser_dialect(db.info.database_type); + Self::from_db_info(&db.info, sql, source_path) + } + + /// Parses and rewrites a SQL file without opening a database connection. + #[must_use] + pub fn from_db_info(database: &DbInfo, sql: &str, source_path: &Path) -> Self { + let dialect = dialect::parser_dialect(database.database_type); log::debug!( "Parsing SQL file {} using dialect {:?}", source_path.display(), dialect ); - let statements = match parse_sql(&db.info, dialect.as_ref(), sql) { + let statements = match parse_sql(database, dialect.as_ref(), sql) { Ok(statements) => statements.collect::>().into_boxed_slice(), Err(error) => { return Self::from_error(error, source_path);