Skip to main content

architect_sdk/db/
mod.rs

1//! Database dialect abstraction for architect-sdk.
2//!
3//! Package configs use canonical type names (see [`types::CanonicalType`]). Each dialect
4//! module maps those to database-specific DDL strings, SQL casts, and operator rules.
5//!
6//! # Adding a new dialect
7//! 1. Add a Cargo feature (e.g. `mysql`).
8//! 2. Create `src/db/your_dialect.rs` implementing [`Dialect`].
9//! 3. Gate it with `#[cfg(feature = "your_dialect")]` below.
10//! 4. Add it to `active_dialect()`.
11//! 5. Add to Cargo.toml features.
12
13pub mod dialect;
14pub mod introspect;
15pub mod pool;
16pub mod types;
17
18pub use dialect::Dialect;
19pub use introspect::{introspect, ColumnFacts, DbSnapshot};
20pub use types::{
21    active_cast_name, parse_canonical, type_category, type_category_from_cast, CanonicalType,
22    TypeCategory, TypeSupport,
23};
24
25#[cfg(feature = "postgres")]
26pub mod postgres;
27#[cfg(feature = "postgres")]
28pub use postgres::PostgresDialect;
29
30#[cfg(feature = "mysql")]
31pub mod mysql;
32#[cfg(feature = "mysql")]
33pub use mysql::MySqlDialect;
34
35#[cfg(feature = "sqlite")]
36pub mod sqlite;
37#[cfg(feature = "sqlite")]
38pub use sqlite::SqliteDialect;
39
40/// Construct the compiled-in dialect as a shared reference.
41/// The dialect is determined at compile time by the active feature flag.
42pub fn active_dialect() -> std::sync::Arc<dyn Dialect> {
43    _active_dialect_impl()
44}
45
46#[cfg(feature = "postgres")]
47fn _active_dialect_impl() -> std::sync::Arc<dyn Dialect> {
48    std::sync::Arc::new(PostgresDialect)
49}
50
51#[cfg(feature = "mysql")]
52fn _active_dialect_impl() -> std::sync::Arc<dyn Dialect> {
53    std::sync::Arc::new(MySqlDialect)
54}
55
56#[cfg(feature = "sqlite")]
57fn _active_dialect_impl() -> std::sync::Arc<dyn Dialect> {
58    std::sync::Arc::new(SqliteDialect)
59}
60
61#[cfg(not(any(feature = "postgres", feature = "mysql", feature = "sqlite")))]
62fn _active_dialect_impl() -> std::sync::Arc<dyn Dialect> {
63    panic!("No database dialect feature enabled. Enable one of: postgres, mysql, sqlite.");
64}