SQLImporter

Struct SQLImporter 

Source
pub struct SQLImporter {
    pub dialect: String,
}
Expand description

SQL Importer - parses CREATE TABLE statements

Fields§

§dialect: String

SQL dialect to use for parsing

Implementations§

Source§

impl SQLImporter

Source

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
    • STRUCT and ARRAY complex types
    • CREATE VIEW and CREATE MATERIALIZED VIEW statements
§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");
Source

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);
Source

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§

Source§

impl Default for SQLImporter

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more