Skip to main content

ferrule_sql/
dialect.rs

1//! SQL dialect classification shared across the driver and write-path
2//! modules.
3//!
4//! [`Dialect`] is a pure data classification of the SQL flavour a
5//! connection speaks, derived from the URL scheme. It carries no driver
6//! dependency and is deliberately not feature-gated so that callers can
7//! reason about portable DDL/query generation regardless of which
8//! backend features are compiled in.
9
10/// SQL dialect of the target database, used to generate portable DDL
11/// and queries.
12///
13/// Derived from the connection URL scheme (see [`Dialect::from_scheme`]).
14/// Deliberately not feature-gated: it is a pure data classification of
15/// the SQL we emit and carries no driver dependency, so it stays
16/// available regardless of which backend features are compiled in.
17#[derive(Debug, Clone, Copy, PartialEq, Eq)]
18pub enum Dialect {
19    Sqlite,
20    Postgres,
21    MySql,
22    MsSql,
23    Oracle,
24}
25
26impl Dialect {
27    /// Map a connection URL scheme to a [`Dialect`].
28    ///
29    /// Returns `None` for unrecognised schemes; callers fall back to
30    /// [`Dialect::Sqlite`] semantics (ANSI `LIMIT`, `TEXT` columns).
31    #[must_use]
32    pub fn from_scheme(scheme: &str) -> Option<Self> {
33        match scheme {
34            "sqlite" => Some(Self::Sqlite),
35            "postgres" | "postgresql" => Some(Self::Postgres),
36            "mysql" | "mariadb" => Some(Self::MySql),
37            "mssql" | "sqlserver" | "tds" => Some(Self::MsSql),
38            "oracle" => Some(Self::Oracle),
39            _ => None,
40        }
41    }
42}