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