pub struct SQLImporter {
pub dialect: String,
}Expand description
SQL Importer - parses CREATE TABLE statements
Fields§
§dialect: StringSQL dialect to use for parsing
Implementations§
Source§impl SQLImporter
impl SQLImporter
Sourcepub fn new(dialect: &str) -> Self
pub fn new(dialect: &str) -> Self
Create a new SQL importer with the specified dialect
§Arguments
dialect- SQL dialect name (“postgres”, “mysql”, “sqlite”, “generic”, “databricks”)
§Supported Dialects
- postgres / postgresql: PostgreSQL dialect
- mysql: MySQL dialect
- sqlite: SQLite dialect
- generic: Generic SQL dialect (default)
- databricks: Databricks SQL dialect with support for:
IDENTIFIER()function calls in table/view names- Variable references (
:variable_name) in type definitions, column definitions, and metadata STRUCTandARRAYcomplex typesCREATE VIEWandCREATE MATERIALIZED VIEWstatements
§Example
use data_modelling_sdk::import::sql::SQLImporter;
// Standard SQL dialect
let importer = SQLImporter::new("postgres");
// Databricks SQL dialect
let databricks_importer = SQLImporter::new("databricks");Sourcepub fn parse(&self, sql: &str) -> Result<ImportResult>
pub fn parse(&self, sql: &str) -> Result<ImportResult>
Parse SQL and extract table definitions
§Arguments
sql- SQL string containing CREATE TABLE, CREATE VIEW, or CREATE MATERIALIZED VIEW statements
§Returns
An ImportResult containing extracted tables/views and any parse errors.
§Example - Standard SQL
use data_modelling_sdk::import::sql::SQLImporter;
let importer = SQLImporter::new("postgres");
let sql = "CREATE TABLE users (id INT PRIMARY KEY, name VARCHAR(100));";
let result = importer.parse(sql).unwrap();
assert_eq!(result.tables.len(), 1);§Example - Databricks SQL with IDENTIFIER()
use data_modelling_sdk::import::sql::SQLImporter;
let importer = SQLImporter::new("databricks");
let sql = "CREATE TABLE IDENTIFIER(:catalog || '.schema.table') (id STRING, name STRING);";
let result = importer.parse(sql).unwrap();
assert_eq!(result.tables.len(), 1);
assert_eq!(result.tables[0].name.as_deref(), Some("schema.table"));§Example - Databricks SQL with Views
use data_modelling_sdk::import::sql::SQLImporter;
let importer = SQLImporter::new("databricks");
let sql = "CREATE VIEW example_view AS SELECT * FROM table1;";
let result = importer.parse(sql).unwrap();
assert_eq!(result.tables.len(), 1);Sourcepub fn parse_liquibase(&self, sql: &str) -> Result<ImportResult>
pub fn parse_liquibase(&self, sql: &str) -> Result<ImportResult>
Parse SQL with Liquibase format support
Strips Liquibase directive comments (–liquibase formatted sql, –changeset, etc.) before parsing the SQL.
§Arguments
sql- SQL string with optional Liquibase comments
§Returns
An ImportResult containing extracted tables.
§Example
use data_modelling_sdk::import::sql::SQLImporter;
let importer = SQLImporter::new("postgres");
let sql = r#"
--liquibase formatted sql
--changeset user:1
CREATE TABLE users (id INT);
"#;
let result = importer.parse_liquibase(sql).unwrap();Trait Implementations§
Auto Trait Implementations§
impl Freeze for SQLImporter
impl RefUnwindSafe for SQLImporter
impl Send for SQLImporter
impl Sync for SQLImporter
impl Unpin for SQLImporter
impl UnwindSafe for SQLImporter
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more