drizzle_core/traits/
mod.rs1use crate::TableRef;
4use crate::prelude::*;
5use core::any::Any;
6
7#[macro_use]
8mod tuple;
9
10mod column;
11mod constraint;
12mod foreign_key;
13mod index;
14mod param;
15mod policy;
16mod primary_key;
17mod table;
18mod to_sql;
19mod type_set;
20mod view;
21
22pub use column::*;
23pub use constraint::*;
24pub use foreign_key::*;
25pub use index::*;
26pub use param::*;
27pub use policy::*;
28pub use primary_key::*;
29pub use table::*;
30pub use to_sql::*;
31pub use type_set::*;
32pub use view::*;
33
34#[diagnostic::on_unimplemented(
38 message = "`{Self}` is not a SQL schema element",
39 label = "this type was not derived with a drizzle schema macro"
40)]
41pub trait SQLSchema<'a, T, V: SQLParam + 'a>: ToSQL<'a, V> {
42 const NAME: &'static str;
43 const TYPE: T;
44 const SQL: &'static str;
46}
47
48impl<'a, S, T, V> SQLSchema<'a, T, V> for &S
49where
50 S: SQLSchema<'a, T, V>,
51 V: SQLParam + 'a,
52{
53 const NAME: &'static str = <S as SQLSchema<'a, T, V>>::NAME;
54 const TYPE: T = <S as SQLSchema<'a, T, V>>::TYPE;
55 const SQL: &'static str = <S as SQLSchema<'a, T, V>>::SQL;
56}
57
58#[diagnostic::on_unimplemented(
63 message = "`{Self}` is not a recognized schema item",
64 label = "schema items must be tables, views, indexes, or enums derived with drizzle macros"
65)]
66pub trait SchemaItemTables {
67 type Tables: TypeSet;
68 const TABLE_REF_CONST: Option<&'static TableRef> = None;
71}
72
73#[diagnostic::on_unimplemented(
75 message = "`{Self}` is not a SQL schema type marker",
76 label = "expected a dialect marker like SQLiteSchemaType or PostgresSchemaType"
77)]
78pub trait SQLSchemaType: core::fmt::Debug + Any + Send + Sync {}
79
80pub trait SQLSchemaImpl: Any + Send + Sync {
82 fn table_refs(&self) -> &'static [&'static TableRef];
83 fn create_statements(&self) -> crate::error::Result<impl Iterator<Item = String>>;
89}