1//! Provides shared types and functions related to working with MySQL and MariaDB
23#[cfg(any(feature = "mysql", feature = "mariadb"))]
4mod connection;
5mod types;
67pub(crate) mod query_builder;
8mod value;
910use core::hash::Hash;
1112use crate::backend::{Backend, DieselReserveSpecialization};
13use crate::mysql_like::query_builder::MysqlLikeQueryBuilder;
14use crate::query_builder::bind_collector::RawBytesBindCollector;
15use crate::result::DatabaseErrorKind;
16use crate::sql_types::TypeMetadata;
1718#[cfg(any(feature = "mysql", feature = "mariadb"))]
19pub use self::connection::MysqlLikeConnection;
20pub use self::value::{MysqlValue, NumericRepresentation};
2122/// Data structures for MySQL types which have no corresponding Rust type
23///
24/// Most of these types are used to implement `ToSql` and `FromSql` for higher
25/// level types.
26pub mod data_types {
27#[doc(inline)]
28pub use super::types::date_and_time::MysqlTime;
29#[doc(inline)]
30pub use super::types::date_and_time::MysqlTimestampType;
31}
3233/// MySQL specific sql types
34pub mod sql_types {
35#[doc(inline)]
36pub use super::types::Datetime;
37#[doc(inline)]
38pub use super::types::Unsigned;
39}
4041/// A trait for backends which implement the MySQL wire protocol. This is implemented for both MySQL and MariaDB,
42/// and can be used when writing code that is compatible with both backends.
43#[cfg_attr(
44 not(feature = "i-implement-a-third-party-backend-and-opt-into-breaking-changes"),
45 expect(private_bounds)
46)]
47pub trait MysqlLikeBackend48where
49Self: for<'a> Backend<
50 RawValue<'a> = MysqlValue<'a>,
51 BindCollector<'a> = RawBytesBindCollector<Self>,
52 >,
53Self: TypeMetadata<TypeMetadata = MysqlType, MetadataLookup = ()>,
54Self: Backend<QueryBuilder = MysqlLikeQueryBuilder<Self>>,
55Self: Hash + Eq + Default,
56Self: DieselReserveSpecialization,
57Self: MapErrorNumber,
58Self: 'static,
59{
60#[doc(hidden)]
61/// The scheme used in the connection URL for this backend.
62 /// "mysql" for MySQL, "mariadb" for MariaDB.
63const SCHEME: &'static str;
64}
6566pub trait MapErrorNumber {
/// Resolve the returned error number to a `DatabaseErrorKind`
fn map_error_number(error_number: u32)
-> DatabaseErrorKind;
}#[diesel_derives::__diesel_public_if(
67 feature = "i-implement-a-third-party-backend-and-opt-into-breaking-changes"
68)]69pub(crate) trait MapErrorNumber {
70/// Resolve the returned error number to a `DatabaseErrorKind`
71// Bound on `MysqlLikeBackend` everywhere, called only by the connections.
72#[cfg_attr(
73 not(any(
74 feature = "mysql",
75 feature = "mariadb",
76 feature = "i-implement-a-third-party-backend-and-opt-into-breaking-changes"
77)),
78 expect(dead_code, reason = "only the connections call it")
79 )]
80fn map_error_number(error_number: u32) -> DatabaseErrorKind;
81}
8283/// Represents possible types, that can be transmitted as via the
84/// Mysql wire protocol
85#[derive(#[automatically_derived]impl ::core::fmt::Debug for MysqlType {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_c_like_enum_write_str(f,
"Tiny UnsignedTiny Short UnsignedShort Long UnsignedLong LongLong UnsignedLongLong Float Double Numeric Time Date DateTime Timestamp String Blob Bit Set Enum",
match self {
MysqlType::Tiny => 0usize,
MysqlType::UnsignedTiny => 5usize,
MysqlType::Short => 18usize,
MysqlType::UnsignedShort => 24usize,
MysqlType::Long => 38usize,
MysqlType::UnsignedLong => 43usize,
MysqlType::LongLong => 56usize,
MysqlType::UnsignedLongLong => 65usize,
MysqlType::Float => 82usize,
MysqlType::Double => 88usize,
MysqlType::Numeric => 95usize,
MysqlType::Time => 103usize,
MysqlType::Date => 108usize,
MysqlType::DateTime => 113usize,
MysqlType::Timestamp => 122usize,
MysqlType::String => 132usize,
MysqlType::Blob => 139usize,
MysqlType::Bit => 144usize,
MysqlType::Set => 148usize,
MysqlType::Enum => 152usize,
})
}
}Debug, #[automatically_derived]impl ::core::hash::Hash for MysqlType {
#[inline]
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
::core::hash::Hash::hash(&::core::intrinsics::discriminant_value(self),
state)
}
}Hash, #[automatically_derived]impl ::core::marker::StructuralPartialEq for MysqlType
{
}
#[automatically_derived]impl ::core::cmp::PartialEq for MysqlType {
#[inline]
fn eq(&self, other: &Self) -> bool {
::core::intrinsics::discriminant_value(self) ==
::core::intrinsics::discriminant_value(other)
}
}PartialEq, #[automatically_derived]impl ::core::cmp::Eq for MysqlType { }Eq, #[automatically_derived]#[doc(hidden)]unsafe impl ::core::clone::TrivialClone
for MysqlType {
}
#[automatically_derived]impl ::core::clone::Clone for MysqlType {
#[inline]
fn clone(&self) -> Self { *self }
}Clone, #[automatically_derived]impl ::core::marker::Copy for MysqlType { }Copy)]
86#[non_exhaustive]
87pub enum MysqlType {
88/// A 8 bit signed integer
89Tiny,
90/// A 8 bit unsigned integer
91UnsignedTiny,
92/// A 16 bit signed integer
93Short,
94/// A 16 bit unsigned integer
95UnsignedShort,
96/// A 32 bit signed integer
97Long,
98/// A 32 bit unsigned integer
99UnsignedLong,
100/// A 64 bit signed integer
101LongLong,
102/// A 64 bit unsigned integer
103UnsignedLongLong,
104/// A 32 bit floating point number
105Float,
106/// A 64 bit floating point number
107Double,
108/// A fixed point decimal value
109Numeric,
110/// A datatype to store a time value
111Time,
112/// A datatype to store a date value
113Date,
114/// A datatype containing timestamp values ranging from
115 /// '1000-01-01 00:00:00' to '9999-12-31 23:59:59'.
116DateTime,
117/// A datatype containing timestamp values ranging from
118 /// 1970-01-01 00:00:01' UTC to '2038-01-19 03:14:07' UTC.
119Timestamp,
120/// A datatype for string values
121String,
122/// A datatype containing binary large objects
123Blob,
124/// A value containing a set of bit's
125Bit,
126/// A user defined set type
127Set,
128/// A user defined enum type
129Enum,
130}
131132pub(crate) mod query_fragments {
133use crate::backend::sql_dialect::batch_update_support::SupportsBatchUpdate;
134use crate::backend::sql_dialect::on_conflict_clause::SupportsOnConflictClause;
135136#[derive(#[automatically_derived]impl ::core::fmt::Debug for
MysqlStyleDefaultValueClause {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::write_str(f, "MysqlStyleDefaultValueClause")
}
}Debug, #[automatically_derived]#[doc(hidden)]unsafe impl ::core::clone::TrivialClone
for MysqlStyleDefaultValueClause {
}
#[automatically_derived]impl ::core::clone::Clone for
MysqlStyleDefaultValueClause {
#[inline]
fn clone(&self) -> Self { *self }
}Clone, #[automatically_derived]impl ::core::marker::Copy for
MysqlStyleDefaultValueClause {
}Copy)]
137pub struct MysqlStyleDefaultValueClause;
138139#[derive(#[automatically_derived]impl ::core::fmt::Debug for MysqlConcatClause {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::write_str(f, "MysqlConcatClause")
}
}Debug, #[automatically_derived]#[doc(hidden)]unsafe impl ::core::clone::TrivialClone
for MysqlConcatClause {
}
#[automatically_derived]impl ::core::clone::Clone for MysqlConcatClause {
#[inline]
fn clone(&self) -> Self { *self }
}Clone, #[automatically_derived]impl ::core::marker::Copy for MysqlConcatClause { }Copy)]
140pub struct MysqlConcatClause;
141142#[derive(#[automatically_derived]impl ::core::fmt::Debug for MysqlOnConflictClause {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::write_str(f, "MysqlOnConflictClause")
}
}Debug, #[automatically_derived]#[doc(hidden)]unsafe impl ::core::clone::TrivialClone
for MysqlOnConflictClause {
}
#[automatically_derived]impl ::core::clone::Clone for MysqlOnConflictClause {
#[inline]
fn clone(&self) -> Self { *self }
}Clone, #[automatically_derived]impl ::core::marker::Copy for MysqlOnConflictClause {
}Copy)]
143pub struct MysqlOnConflictClause;
144145#[derive(#[automatically_derived]impl ::core::fmt::Debug for
MysqlRequiresOrderForWindowFunctions {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::write_str(f,
"MysqlRequiresOrderForWindowFunctions")
}
}Debug, #[automatically_derived]#[doc(hidden)]unsafe impl ::core::clone::TrivialClone
for MysqlRequiresOrderForWindowFunctions {
}
#[automatically_derived]impl ::core::clone::Clone for
MysqlRequiresOrderForWindowFunctions {
#[inline]
fn clone(&self) -> Self { *self }
}Clone, #[automatically_derived]impl ::core::marker::Copy for
MysqlRequiresOrderForWindowFunctions {
}Copy)]
146pub struct MysqlRequiresOrderForWindowFunctions;
147148impl SupportsOnConflictClausefor MysqlOnConflictClause {}
149150#[derive(#[automatically_derived]impl ::core::fmt::Debug for
MySqlLikeBatchUpdateSupport {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::write_str(f, "MySqlLikeBatchUpdateSupport")
}
}Debug, #[automatically_derived]#[doc(hidden)]unsafe impl ::core::clone::TrivialClone
for MySqlLikeBatchUpdateSupport {
}
#[automatically_derived]impl ::core::clone::Clone for
MySqlLikeBatchUpdateSupport {
#[inline]
fn clone(&self) -> Self { *self }
}Clone, #[automatically_derived]impl ::core::marker::Copy for
MySqlLikeBatchUpdateSupport {
}Copy)]
151pub struct MySqlLikeBatchUpdateSupport;
152153impl SupportsBatchUpdatefor MySqlLikeBatchUpdateSupport {}
154}