safe_migrate/engine/
mod.rs1#![allow(clippy::module_inception)]
3
4pub mod config;
5pub mod engine;
6
7#[cfg(test)]
8mod tests;
9
10use squawk_syntax::ast::SourceFile;
11use squawk_syntax::ast::Stmt;
12
13pub struct MigrationFile {
16 source: SourceFile,
17}
18
19impl MigrationFile {
20 pub fn parse(sql: &str) -> Result<Self, Vec<String>> {
21 let parsed = SourceFile::parse(sql);
22 let errors: Vec<String> = parsed.errors().iter().map(|e| e.to_string()).collect();
23
24 if !errors.is_empty() {
25 return Err(errors);
26 }
27
28 Ok(Self {
29 source: parsed.tree(),
30 })
31 }
32
33 pub fn statements(&self) -> impl Iterator<Item = Stmt> + '_ {
34 self.source.stmts()
35 }
36}