sql_lsp/dialects/
mod.rs

1pub mod clickhouse;
2pub mod elasticsearch_dsl;
3pub mod elasticsearch_eql;
4pub mod hive;
5pub mod mysql;
6pub mod postgres;
7pub mod redis;
8
9pub use clickhouse::ClickHouseDialect;
10pub use elasticsearch_dsl::ElasticsearchDslDialect;
11pub use elasticsearch_eql::ElasticsearchEqlDialect;
12pub use hive::HiveDialect;
13pub use mysql::MysqlDialect;
14pub use postgres::PostgresDialect;
15pub use redis::RedisDialect;
16
17use crate::dialect::Dialect;
18use std::sync::Arc;
19
20/// 方言注册表
21pub struct DialectRegistry {
22    dialects: Vec<Arc<dyn Dialect>>,
23}
24
25impl DialectRegistry {
26    pub fn new() -> Self {
27        let mut registry = Self {
28            dialects: Vec::new(),
29        };
30
31        // 注册所有方言
32        registry.register(Arc::new(MysqlDialect::new()));
33        registry.register(Arc::new(PostgresDialect::new()));
34        registry.register(Arc::new(HiveDialect::new()));
35        registry.register(Arc::new(ElasticsearchEqlDialect::new()));
36        registry.register(Arc::new(ElasticsearchDslDialect::new()));
37        registry.register(Arc::new(ClickHouseDialect::new()));
38        registry.register(Arc::new(RedisDialect::new()));
39
40        registry
41    }
42
43    pub fn register(&mut self, dialect: Arc<dyn Dialect>) {
44        self.dialects.push(dialect);
45    }
46
47    pub fn get_by_name(&self, name: &str) -> Option<Arc<dyn Dialect>> {
48        self.dialects
49            .iter()
50            .find(|d| d.name().eq_ignore_ascii_case(name))
51            .cloned()
52    }
53
54    pub fn list_names(&self) -> Vec<String> {
55        self.dialects.iter().map(|d| d.name().to_string()).collect()
56    }
57}
58
59impl Default for DialectRegistry {
60    fn default() -> Self {
61        Self::new()
62    }
63}