Skip to main content

sqruff_lib_dialects/
lib.rs

1use sqruff_lib_core::dialects::Dialect;
2use sqruff_lib_core::dialects::init::DialectKind;
3use sqruff_lib_core::value::Value;
4
5pub mod ansi;
6mod ansi_keywords;
7#[cfg(feature = "athena")]
8pub mod athena;
9#[cfg(feature = "athena")]
10mod athena_keywords;
11#[cfg(feature = "bigquery")]
12pub mod bigquery;
13#[cfg(feature = "bigquery")]
14mod bigquery_keywords;
15#[cfg(feature = "clickhouse")]
16pub mod clickhouse;
17#[cfg(feature = "clickhouse")]
18mod clickhouse_keywords;
19#[cfg(feature = "databricks")]
20pub mod databricks;
21#[cfg(feature = "databricks")]
22pub mod databricks_keywords;
23#[cfg(feature = "db2")]
24pub mod db2;
25#[cfg(feature = "db2")]
26mod db2_keywords;
27#[cfg(feature = "duckdb")]
28pub mod duckdb;
29#[cfg(feature = "hive")]
30pub mod hive;
31#[cfg(feature = "mysql")]
32pub mod mysql;
33#[cfg(feature = "mysql")]
34mod mysql_keywords;
35#[cfg(feature = "oracle")]
36pub mod oracle;
37#[cfg(feature = "postgres")]
38pub mod postgres;
39#[cfg(feature = "postgres")]
40mod postgres_keywords;
41#[cfg(feature = "redshift")]
42pub mod redshift;
43#[cfg(feature = "redshift")]
44mod redshift_keywords;
45#[cfg(feature = "snowflake")]
46pub mod snowflake;
47#[cfg(feature = "snowflake")]
48mod snowflake_keywords;
49#[cfg(feature = "sparksql")]
50pub mod sparksql;
51#[cfg(feature = "sparksql")]
52mod sparksql_keywords;
53#[cfg(feature = "sqlite")]
54pub mod sqlite;
55#[cfg(feature = "sqlite")]
56mod sqlite_keywords;
57#[cfg(feature = "trino")]
58pub mod trino;
59#[cfg(feature = "trino")]
60mod trino_keywords;
61#[cfg(feature = "tsql")]
62pub mod tsql;
63#[cfg(feature = "tsql")]
64mod tsql_keywords;
65
66/// Returns dialect-specific configuration options for the given dialect kind.
67/// Each entry is (option_name, description, default_value).
68pub fn dialect_config_options(
69    kind: &DialectKind,
70) -> Vec<(&'static str, &'static str, &'static str)> {
71    #[allow(unreachable_patterns)]
72    match kind {
73        DialectKind::Ansi => ansi::AnsiDialectConfig::config_options(),
74        #[cfg(feature = "athena")]
75        DialectKind::Athena => athena::AthenaDialectConfig::config_options(),
76        #[cfg(feature = "bigquery")]
77        DialectKind::Bigquery => bigquery::BigQueryDialectConfig::config_options(),
78        #[cfg(feature = "clickhouse")]
79        DialectKind::Clickhouse => clickhouse::ClickHouseDialectConfig::config_options(),
80        #[cfg(feature = "databricks")]
81        DialectKind::Databricks => databricks::DatabricksDialectConfig::config_options(),
82        #[cfg(feature = "db2")]
83        DialectKind::Db2 => db2::Db2DialectConfig::config_options(),
84        #[cfg(feature = "duckdb")]
85        DialectKind::Duckdb => duckdb::DuckDBDialectConfig::config_options(),
86        #[cfg(feature = "mysql")]
87        DialectKind::Mysql => mysql::MySQLDialectConfig::config_options(),
88        #[cfg(feature = "oracle")]
89        DialectKind::Oracle => oracle::OracleDialectConfig::config_options(),
90        #[cfg(feature = "postgres")]
91        DialectKind::Postgres => postgres::PostgresDialectConfig::config_options(),
92        #[cfg(feature = "redshift")]
93        DialectKind::Redshift => redshift::RedshiftDialectConfig::config_options(),
94        #[cfg(feature = "snowflake")]
95        DialectKind::Snowflake => snowflake::SnowflakeDialectConfig::config_options(),
96        #[cfg(feature = "sparksql")]
97        DialectKind::Sparksql => sparksql::SparkSQLDialectConfig::config_options(),
98        #[cfg(feature = "sqlite")]
99        DialectKind::Sqlite => sqlite::SQLiteDialectConfig::config_options(),
100        #[cfg(feature = "trino")]
101        DialectKind::Trino => trino::TrinoDialectConfig::config_options(),
102        #[cfg(feature = "tsql")]
103        DialectKind::Tsql => tsql::TSQLDialectConfig::config_options(),
104        _ => vec![],
105    }
106}
107
108pub fn kind_to_dialect(kind: &DialectKind, config: Option<&Value>) -> Option<Dialect> {
109    #[allow(unreachable_patterns)]
110    Some(match kind {
111        DialectKind::Ansi => ansi::dialect(config),
112        #[cfg(feature = "athena")]
113        DialectKind::Athena => athena::dialect(config),
114        #[cfg(feature = "bigquery")]
115        DialectKind::Bigquery => bigquery::dialect(config),
116        #[cfg(feature = "clickhouse")]
117        DialectKind::Clickhouse => clickhouse::dialect(config),
118        #[cfg(feature = "databricks")]
119        DialectKind::Databricks => databricks::dialect(config),
120        #[cfg(feature = "db2")]
121        DialectKind::Db2 => db2::dialect(config),
122        #[cfg(feature = "duckdb")]
123        DialectKind::Duckdb => duckdb::dialect(config),
124        #[cfg(feature = "mysql")]
125        DialectKind::Mysql => mysql::dialect(config),
126        #[cfg(feature = "oracle")]
127        DialectKind::Oracle => oracle::dialect(config),
128        #[cfg(feature = "postgres")]
129        DialectKind::Postgres => postgres::dialect(config),
130        #[cfg(feature = "redshift")]
131        DialectKind::Redshift => redshift::dialect(config),
132        #[cfg(feature = "snowflake")]
133        DialectKind::Snowflake => snowflake::dialect(config),
134        #[cfg(feature = "sparksql")]
135        DialectKind::Sparksql => sparksql::dialect(config),
136        #[cfg(feature = "sqlite")]
137        DialectKind::Sqlite => sqlite::dialect(config),
138        #[cfg(feature = "trino")]
139        DialectKind::Trino => trino::dialect(config),
140        #[cfg(feature = "tsql")]
141        DialectKind::Tsql => tsql::dialect(config),
142        _ => return None,
143    })
144}