drizzle_core/traits/
mod.rs

1//! Core traits for SQL generation.
2
3use crate::prelude::*;
4use core::any::Any;
5
6mod column;
7mod index;
8mod param;
9mod table;
10mod to_sql;
11mod tuple;
12mod view;
13
14pub use column::*;
15pub use index::*;
16pub use param::*;
17pub use table::*;
18pub use to_sql::*;
19pub use view::*;
20
21use crate::sql::SQL;
22
23/// Trait for schema elements (tables, columns, etc.).
24///
25/// The `'a` lifetime ties any borrowed parameter values to generated SQL.
26pub trait SQLSchema<'a, T, V: SQLParam + 'a>: ToSQL<'a, V> {
27    const NAME: &'a str;
28    const TYPE: T;
29    /// Static SQL string for schema creation (e.g., CREATE TABLE ...)
30    const SQL: &'static str;
31
32    /// Generate SQL for this schema element.
33    /// Default implementation wraps the static SQL string.
34    fn sql(&self) -> SQL<'a, V> {
35        SQL::raw(Self::SQL)
36    }
37}
38
39/// Marker trait for schema types (used for type-level discrimination).
40pub trait SQLSchemaType: core::fmt::Debug + Any + Send + Sync {}
41
42/// Trait for schema implementations that can generate CREATE statements.
43pub trait SQLSchemaImpl: Any + Send + Sync {
44    fn create_statements(&self) -> Vec<String>;
45}
46
47/// Marker trait for types that can be compared in SQL expressions.
48pub trait SQLComparable<'a, V: SQLParam, Rhs> {}
49
50impl<'a, V, L, R> SQLComparable<'a, V, R> for L
51where
52    V: SQLParam + 'a,
53    L: ToSQL<'a, V>,
54    R: ToSQL<'a, V>,
55{
56}