use sqlparser::dialect;
use sqlparser::dialect::Dialect;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum DialectName {
Generic,
MySql,
PostgreSql,
Hive,
SQLite,
Snowflake,
Redshift,
MsSql,
ClickHouse,
BigQuery,
Ansi,
DuckDb,
Databricks,
Oracle,
}
impl DialectName {
pub fn all() -> [DialectName; 14] {
[
Self::Generic,
Self::MySql,
Self::PostgreSql,
Self::Hive,
Self::SQLite,
Self::Snowflake,
Self::Redshift,
Self::MsSql,
Self::ClickHouse,
Self::BigQuery,
Self::Ansi,
Self::DuckDb,
Self::Databricks,
Self::Oracle,
]
}
pub fn instance(self) -> Box<dyn Dialect> {
match self {
Self::Generic => Box::new(dialect::GenericDialect {}),
Self::MySql => Box::new(dialect::MySqlDialect {}),
Self::PostgreSql => Box::new(dialect::PostgreSqlDialect {}),
Self::Hive => Box::new(dialect::HiveDialect {}),
Self::SQLite => Box::new(dialect::SQLiteDialect {}),
Self::Snowflake => Box::new(dialect::SnowflakeDialect {}),
Self::Redshift => Box::new(dialect::RedshiftSqlDialect {}),
Self::MsSql => Box::new(dialect::MsSqlDialect {}),
Self::ClickHouse => Box::new(dialect::ClickHouseDialect {}),
Self::BigQuery => Box::new(dialect::BigQueryDialect {}),
Self::Ansi => Box::new(dialect::AnsiDialect {}),
Self::DuckDb => Box::new(dialect::DuckDbDialect {}),
Self::Databricks => Box::new(dialect::DatabricksDialect {}),
Self::Oracle => Box::new(dialect::OracleDialect {}),
}
}
}
pub fn all_dialects() -> Vec<Box<dyn Dialect>> {
DialectName::all()
.into_iter()
.map(|n| n.instance())
.collect()
}
pub fn all_dialects_except(exclude: &[DialectName]) -> Vec<Box<dyn Dialect>> {
DialectName::all()
.into_iter()
.filter(|n| !exclude.contains(n))
.map(|n| n.instance())
.collect()
}