pub use drizzle_types::Dialect;
#[derive(Debug, Clone, Copy)]
pub struct SQLiteDialect;
#[derive(Debug, Clone, Copy)]
pub struct PostgresDialect;
use crate::types::{Binary, BooleanLike, DataType, Floating, Integral, Temporal, Textual};
pub trait DialectTypes {
type SmallInt: DataType + Integral;
type Int: DataType + Integral;
type BigInt: DataType + Integral;
type Float: DataType + Floating;
type Double: DataType + Floating;
type Text: DataType + Textual;
type Bool: DataType + BooleanLike;
type Bytes: DataType + Binary;
type Date: DataType + Temporal;
type Time: DataType + Temporal;
type Timestamp: DataType + Temporal;
type TimestampTz: DataType + Temporal;
type Uuid: DataType;
type Json: DataType;
type Jsonb: DataType;
type Any: DataType;
}
impl DialectTypes for SQLiteDialect {
type SmallInt = drizzle_types::sqlite::types::Integer;
type Int = drizzle_types::sqlite::types::Integer;
type BigInt = drizzle_types::sqlite::types::Integer;
type Float = drizzle_types::sqlite::types::Real;
type Double = drizzle_types::sqlite::types::Real;
type Text = drizzle_types::sqlite::types::Text;
type Bool = drizzle_types::sqlite::types::Integer;
type Bytes = drizzle_types::sqlite::types::Blob;
type Date = drizzle_types::sqlite::types::Text;
type Time = drizzle_types::sqlite::types::Text;
type Timestamp = drizzle_types::sqlite::types::Text;
type TimestampTz = drizzle_types::sqlite::types::Text;
type Uuid = drizzle_types::sqlite::types::Blob;
type Json = drizzle_types::sqlite::types::Text;
type Jsonb = drizzle_types::sqlite::types::Text;
type Any = drizzle_types::sqlite::types::Any;
}
impl DialectTypes for PostgresDialect {
type SmallInt = drizzle_types::postgres::types::Int2;
type Int = drizzle_types::postgres::types::Int4;
type BigInt = drizzle_types::postgres::types::Int8;
type Float = drizzle_types::postgres::types::Float4;
type Double = drizzle_types::postgres::types::Float8;
type Text = drizzle_types::postgres::types::Text;
type Bool = drizzle_types::postgres::types::Boolean;
type Bytes = drizzle_types::postgres::types::Bytea;
type Date = drizzle_types::postgres::types::Date;
type Time = drizzle_types::postgres::types::Time;
type Timestamp = drizzle_types::postgres::types::Timestamp;
type TimestampTz = drizzle_types::postgres::types::Timestamptz;
type Uuid = drizzle_types::postgres::types::Uuid;
type Json = drizzle_types::postgres::types::Json;
type Jsonb = drizzle_types::postgres::types::Jsonb;
type Any = drizzle_types::postgres::types::Any;
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ParamStyle {
DollarNumbered,
Question,
ColonNumbered,
}
impl ParamStyle {
#[inline]
#[must_use]
pub const fn for_dialect(dialect: Dialect) -> Self {
match dialect {
Dialect::PostgreSQL => Self::DollarNumbered,
Dialect::SQLite | Dialect::MySQL => Self::Question,
}
}
#[inline]
pub fn write(self, index: usize, buf: &mut impl core::fmt::Write) {
match self {
Self::DollarNumbered => {
let _ = buf.write_char('$');
let _ = write!(buf, "{index}");
}
Self::ColonNumbered => {
let _ = buf.write_char(':');
let _ = write!(buf, "{index}");
}
Self::Question => {
let _ = buf.write_char('?');
}
}
}
}
#[inline]
pub fn write_placeholder(dialect: Dialect, index: usize, buf: &mut impl core::fmt::Write) {
ParamStyle::for_dialect(dialect).write(index, buf);
}