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 = "duckdb")]
24pub mod duckdb;
25#[cfg(feature = "hive")]
26pub mod hive;
27#[cfg(feature = "mysql")]
28pub mod mysql;
29#[cfg(feature = "postgres")]
30pub mod postgres;
31#[cfg(feature = "postgres")]
32mod postgres_keywords;
33#[cfg(feature = "redshift")]
34pub mod redshift;
35#[cfg(feature = "redshift")]
36mod redshift_keywords;
37#[cfg(feature = "snowflake")]
38pub mod snowflake;
39#[cfg(feature = "snowflake")]
40mod snowflake_keywords;
41#[cfg(feature = "sparksql")]
42pub mod sparksql;
43#[cfg(feature = "sparksql")]
44mod sparksql_keywords;
45#[cfg(feature = "sqlite")]
46pub mod sqlite;
47#[cfg(feature = "sqlite")]
48mod sqlite_keywords;
49#[cfg(feature = "trino")]
50pub mod trino;
51#[cfg(feature = "trino")]
52mod trino_keywords;
53#[cfg(feature = "tsql")]
54pub mod tsql;
55#[cfg(feature = "tsql")]
56mod tsql_keywords;
57
58/// Returns dialect-specific configuration options for the given dialect kind.
59/// Each entry is (option_name, description, default_value).
60pub fn dialect_config_options(
61    kind: &DialectKind,
62) -> Vec<(&'static str, &'static str, &'static str)> {
63    #[allow(unreachable_patterns)]
64    match kind {
65        DialectKind::Ansi => ansi::AnsiDialectConfig::config_options(),
66        #[cfg(feature = "athena")]
67        DialectKind::Athena => athena::AthenaDialectConfig::config_options(),
68        #[cfg(feature = "bigquery")]
69        DialectKind::Bigquery => bigquery::BigQueryDialectConfig::config_options(),
70        #[cfg(feature = "clickhouse")]
71        DialectKind::Clickhouse => clickhouse::ClickHouseDialectConfig::config_options(),
72        #[cfg(feature = "databricks")]
73        DialectKind::Databricks => databricks::DatabricksDialectConfig::config_options(),
74        #[cfg(feature = "duckdb")]
75        DialectKind::Duckdb => duckdb::DuckDBDialectConfig::config_options(),
76        #[cfg(feature = "mysql")]
77        DialectKind::Mysql => mysql::MySQLDialectConfig::config_options(),
78        #[cfg(feature = "postgres")]
79        DialectKind::Postgres => postgres::PostgresDialectConfig::config_options(),
80        #[cfg(feature = "redshift")]
81        DialectKind::Redshift => redshift::RedshiftDialectConfig::config_options(),
82        #[cfg(feature = "snowflake")]
83        DialectKind::Snowflake => snowflake::SnowflakeDialectConfig::config_options(),
84        #[cfg(feature = "sparksql")]
85        DialectKind::Sparksql => sparksql::SparkSQLDialectConfig::config_options(),
86        #[cfg(feature = "sqlite")]
87        DialectKind::Sqlite => sqlite::SQLiteDialectConfig::config_options(),
88        #[cfg(feature = "trino")]
89        DialectKind::Trino => trino::TrinoDialectConfig::config_options(),
90        #[cfg(feature = "tsql")]
91        DialectKind::Tsql => tsql::TSQLDialectConfig::config_options(),
92        _ => vec![],
93    }
94}
95
96pub fn kind_to_dialect(kind: &DialectKind, config: Option<&Value>) -> Option<Dialect> {
97    #[allow(unreachable_patterns)]
98    Some(match kind {
99        DialectKind::Ansi => ansi::dialect(config),
100        #[cfg(feature = "athena")]
101        DialectKind::Athena => athena::dialect(config),
102        #[cfg(feature = "bigquery")]
103        DialectKind::Bigquery => bigquery::dialect(config),
104        #[cfg(feature = "clickhouse")]
105        DialectKind::Clickhouse => clickhouse::dialect(config),
106        #[cfg(feature = "databricks")]
107        DialectKind::Databricks => databricks::dialect(config),
108        #[cfg(feature = "duckdb")]
109        DialectKind::Duckdb => duckdb::dialect(config),
110        #[cfg(feature = "mysql")]
111        DialectKind::Mysql => mysql::dialect(config),
112        #[cfg(feature = "postgres")]
113        DialectKind::Postgres => postgres::dialect(config),
114        #[cfg(feature = "redshift")]
115        DialectKind::Redshift => redshift::dialect(config),
116        #[cfg(feature = "snowflake")]
117        DialectKind::Snowflake => snowflake::dialect(config),
118        #[cfg(feature = "sparksql")]
119        DialectKind::Sparksql => sparksql::dialect(config),
120        #[cfg(feature = "sqlite")]
121        DialectKind::Sqlite => sqlite::dialect(config),
122        #[cfg(feature = "trino")]
123        DialectKind::Trino => trino::dialect(config),
124        #[cfg(feature = "tsql")]
125        DialectKind::Tsql => tsql::dialect(config),
126        _ => return None,
127    })
128}