Skip to content

Commit 4969cf4

Browse files
authored
Decouple SQL file parsing from database connections (#1556)
1 parent 3b33609 commit 4969cf4

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

‎src/webserver/database/sql.rs‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,19 @@ pub(super) use statement::{OutputColumn, SourceLocation};
5151
impl SqlFile {
5252
#[must_use]
5353
pub fn new(db: &Database, sql: &str, source_path: &Path) -> Self {
54-
let dialect = dialect::parser_dialect(db.info.database_type);
54+
Self::from_db_info(&db.info, sql, source_path)
55+
}
56+
57+
/// Parses and rewrites a SQL file without opening a database connection.
58+
#[must_use]
59+
pub fn from_db_info(database: &DbInfo, sql: &str, source_path: &Path) -> Self {
60+
let dialect = dialect::parser_dialect(database.database_type);
5561
log::debug!(
5662
"Parsing SQL file {} using dialect {:?}",
5763
source_path.display(),
5864
dialect
5965
);
60-
let statements = match parse_sql(&db.info, dialect.as_ref(), sql) {
66+
let statements = match parse_sql(database, dialect.as_ref(), sql) {
6167
Ok(statements) => statements.collect::<Vec<_>>().into_boxed_slice(),
6268
Err(error) => {
6369
return Self::from_error(error, source_path);

0 commit comments

Comments
 (0)