1pub use drizzle_types::Dialect;
5
6#[derive(Debug, Clone, Copy)]
15pub struct SQLiteDialect;
16
17#[derive(Debug, Clone, Copy)]
23pub struct PostgresDialect;
24
25use crate::types::{Binary, BooleanLike, DataType, Floating, Integral, Temporal, Textual};
30
31pub trait DialectTypes {
37 type SmallInt: DataType + Integral;
38 type Int: DataType + Integral;
39 type BigInt: DataType + Integral;
40 type Float: DataType + Floating;
41 type Double: DataType + Floating;
42 type Text: DataType + Textual;
43 type Bool: DataType + BooleanLike;
44 type Bytes: DataType + Binary;
45 type Date: DataType + Temporal;
46 type Time: DataType + Temporal;
47 type Timestamp: DataType + Temporal;
48 type TimestampTz: DataType + Temporal;
49 type Uuid: DataType;
50 type Json: DataType;
51 type Jsonb: DataType;
52 type Any: DataType;
53}
54
55impl DialectTypes for SQLiteDialect {
56 type SmallInt = drizzle_types::sqlite::types::Integer;
57 type Int = drizzle_types::sqlite::types::Integer;
58 type BigInt = drizzle_types::sqlite::types::Integer;
59 type Float = drizzle_types::sqlite::types::Real;
60 type Double = drizzle_types::sqlite::types::Real;
61 type Text = drizzle_types::sqlite::types::Text;
62 type Bool = drizzle_types::sqlite::types::Integer;
63 type Bytes = drizzle_types::sqlite::types::Blob;
64 type Date = drizzle_types::sqlite::types::Text;
65 type Time = drizzle_types::sqlite::types::Text;
66 type Timestamp = drizzle_types::sqlite::types::Text;
67 type TimestampTz = drizzle_types::sqlite::types::Text;
68 type Uuid = drizzle_types::sqlite::types::Text;
69 type Json = drizzle_types::sqlite::types::Text;
70 type Jsonb = drizzle_types::sqlite::types::Text;
71 type Any = drizzle_types::sqlite::types::Any;
72}
73
74impl DialectTypes for PostgresDialect {
75 type SmallInt = drizzle_types::postgres::types::Int2;
76 type Int = drizzle_types::postgres::types::Int4;
77 type BigInt = drizzle_types::postgres::types::Int8;
78 type Float = drizzle_types::postgres::types::Float4;
79 type Double = drizzle_types::postgres::types::Float8;
80 type Text = drizzle_types::postgres::types::Text;
81 type Bool = drizzle_types::postgres::types::Boolean;
82 type Bytes = drizzle_types::postgres::types::Bytea;
83 type Date = drizzle_types::postgres::types::Date;
84 type Time = drizzle_types::postgres::types::Time;
85 type Timestamp = drizzle_types::postgres::types::Timestamp;
86 type TimestampTz = drizzle_types::postgres::types::Timestamptz;
87 type Uuid = drizzle_types::postgres::types::Uuid;
88 type Json = drizzle_types::postgres::types::Json;
89 type Jsonb = drizzle_types::postgres::types::Jsonb;
90 type Any = drizzle_types::postgres::types::Any;
91}
92
93#[derive(Debug, Clone, Copy, PartialEq, Eq)]
100pub enum ParamStyle {
101 DollarNumbered,
103 Question,
105 ColonNumbered,
110}
111
112impl ParamStyle {
113 #[inline]
116 #[must_use]
117 pub const fn for_dialect(dialect: Dialect) -> Self {
118 match dialect {
119 Dialect::PostgreSQL => Self::DollarNumbered,
120 Dialect::SQLite | Dialect::MySQL => Self::Question,
121 }
122 }
123
124 #[inline]
126 pub fn write(self, index: usize, buf: &mut impl core::fmt::Write) {
127 match self {
128 Self::DollarNumbered => {
129 let _ = buf.write_char('$');
130 let _ = write!(buf, "{index}");
131 }
132 Self::ColonNumbered => {
133 let _ = buf.write_char(':');
134 let _ = write!(buf, "{index}");
135 }
136 Self::Question => {
137 let _ = buf.write_char('?');
138 }
139 }
140 }
141}
142
143#[inline]
148pub fn write_placeholder(dialect: Dialect, index: usize, buf: &mut impl core::fmt::Write) {
149 ParamStyle::for_dialect(dialect).write(index, buf);
150}