pub use drizzle_types::Dialect;
#[derive(Debug, Clone, Copy)]
pub struct SQLiteDialect;
#[derive(Debug, Clone, Copy)]
pub struct PostgresDialect;
#[derive(Debug, Clone, Copy)]
pub struct MySQLDialect;
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;
type Random: DataType;
type Sign: DataType;
type DomainNullable<Input: crate::expr::Nullability>: crate::expr::Nullability;
const CHAR_LENGTH_FN: &'static str;
}
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;
type Random = drizzle_types::sqlite::types::Integer;
type Sign = drizzle_types::sqlite::types::Integer;
type DomainNullable<Input: crate::expr::Nullability> = crate::expr::Null;
const CHAR_LENGTH_FN: &'static str = "LENGTH";
}
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;
type Random = drizzle_types::postgres::types::Float8;
type Sign = drizzle_types::postgres::types::Float8;
type DomainNullable<Input: crate::expr::Nullability> = Input;
const CHAR_LENGTH_FN: &'static str = "CHAR_LENGTH";
}
impl DialectTypes for MySQLDialect {
type SmallInt = drizzle_types::mysql::types::SmallInt;
type Int = drizzle_types::mysql::types::Int;
type BigInt = drizzle_types::mysql::types::BigInt;
type Float = drizzle_types::mysql::types::Float;
type Double = drizzle_types::mysql::types::Double;
type Text = drizzle_types::mysql::types::Text;
type Bool = drizzle_types::mysql::types::Boolean;
type Bytes = drizzle_types::mysql::types::Blob;
type Date = drizzle_types::mysql::types::Date;
type Time = drizzle_types::mysql::types::Time;
type Timestamp = drizzle_types::mysql::types::DateTime;
type TimestampTz = drizzle_types::mysql::types::Timestamp;
type Uuid = drizzle_types::mysql::types::Binary;
type Json = drizzle_types::mysql::types::Json;
type Jsonb = drizzle_types::mysql::types::Json;
type Any = drizzle_types::mysql::types::Any;
type Random = drizzle_types::mysql::types::Double;
type Sign = drizzle_types::mysql::types::BigInt;
type DomainNullable<Input: crate::expr::Nullability> = crate::expr::Null;
const CHAR_LENGTH_FN: &'static str = "CHAR_LENGTH";
}
#[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);
}
pub mod feature {
#[derive(Debug, Clone, Copy, Default)]
pub struct SQLiteDateTime;
#[derive(Debug, Clone, Copy, Default)]
pub struct PostgresDateTime;
#[derive(Debug, Clone, Copy, Default)]
pub struct Sequence;
#[derive(Debug, Clone, Copy, Default)]
pub struct Typeof;
#[derive(Debug, Clone, Copy, Default)]
pub struct Excluded;
#[derive(Debug, Clone, Copy, Default)]
pub struct AggregateFilter;
#[derive(Debug, Clone, Copy, Default)]
pub struct PostgresAggregate;
#[derive(Debug, Clone, Copy, Default)]
pub struct SQLiteAggregate;
#[derive(Debug, Clone, Copy, Default)]
pub struct GroupConcat;
#[derive(Debug, Clone, Copy, Default)]
pub struct PostgresString;
#[derive(Debug, Clone, Copy, Default)]
pub struct LeftRight;
#[derive(Debug, Clone, Copy, Default)]
pub struct Pad;
#[derive(Debug, Clone, Copy, Default)]
pub struct Reverse;
#[derive(Debug, Clone, Copy, Default)]
pub struct Repeat;
}
#[diagnostic::on_unimplemented(
message = "`{Feature}` is not available for `{Self}`",
label = "this function is not supported by this dialect",
note = "use a dialect-specific alternative"
)]
pub trait DialectSupports<Feature> {}