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};
21#[doc(inline)]
22pub use sqlstate::mysql_likeas sql_state;
2324/// Data structures for MySQL types which have no corresponding Rust type
25///
26/// Most of these types are used to implement `ToSql` and `FromSql` for higher
27/// level types.
28pub mod data_types {
29#[doc(inline)]
30pub use super::types::date_and_time::MysqlTime;
31#[doc(inline)]
32pub use super::types::date_and_time::MysqlTimestampType;
33}
3435/// MySQL specific sql types
36pub mod sql_types {
37#[doc(inline)]
38pub use super::types::Datetime;
39#[doc(inline)]
40pub use super::types::Unsigned;
41}
4243/// A trait for backends which implement the MySQL wire protocol. This is implemented for both MySQL and MariaDB,
44/// and can be used when writing code that is compatible with both backends.
45#[cfg_attr(
46 not(feature = "i-implement-a-third-party-backend-and-opt-into-breaking-changes"),
47 expect(private_bounds)
48)]
49pub trait MysqlLikeBackend50where
51Self: for<'a> Backend<
52 RawValue<'a> = MysqlValue<'a>,
53 BindCollector<'a> = RawBytesBindCollector<Self>,
54 >,
55Self: TypeMetadata<TypeMetadata = MysqlType, MetadataLookup = ()>,
56Self: Backend<QueryBuilder = MysqlLikeQueryBuilder<Self>>,
57Self: Hash + Eq + Default,
58Self: DieselReserveSpecialization,
59Self: MapErrorNumber,
60Self: 'static,
61{
62#[doc(hidden)]
63/// The scheme used in the connection URL for this backend.
64 /// "mysql" for MySQL, "mariadb" for MariaDB.
65const SCHEME: &'static str;
66}
6768#[doc =
" A helper trait to map error numbers to database error kinds for mysql like backends"]
pub trait MapErrorNumber {
/// Resolve the returned error number to a `DatabaseErrorKind`
fn map_error_number(error_number: u32)
-> DatabaseErrorKind;
}#[diesel_derives::__diesel_public_if(
69 feature = "i-implement-a-third-party-backend-and-opt-into-breaking-changes"
70)]71/// A helper trait to map error numbers to database error kinds for mysql like backends
72pub(crate) trait MapErrorNumber {
73/// Resolve the returned error number to a `DatabaseErrorKind`
74// Bound on `MysqlLikeBackend` everywhere, called only by the connections.
75#[cfg_attr(
76 not(any(
77 feature = "mysql",
78 feature = "mariadb",
79 feature = "i-implement-a-third-party-backend-and-opt-into-breaking-changes"
80)),
81 expect(dead_code, reason = "only the connections call it")
82 )]
83fn map_error_number(error_number: u32) -> DatabaseErrorKind;
84}
8586/// Represents possible types, that can be transmitted as via the
87/// Mysql wire protocol
88#[derive(#[automatically_derived]impl ::core::fmt::Debug for MysqlType {
#[inline]
#[rustc_trivial_field_reads]
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]
#[rustc_trivial_field_reads]
fn clone(&self) -> Self { *self }
}Clone, #[automatically_derived]impl ::core::marker::Copy for MysqlType { }Copy)]
89#[non_exhaustive]
90pub enum MysqlType {
91/// A 8 bit signed integer
92Tiny,
93/// A 8 bit unsigned integer
94UnsignedTiny,
95/// A 16 bit signed integer
96Short,
97/// A 16 bit unsigned integer
98UnsignedShort,
99/// A 32 bit signed integer
100Long,
101/// A 32 bit unsigned integer
102UnsignedLong,
103/// A 64 bit signed integer
104LongLong,
105/// A 64 bit unsigned integer
106UnsignedLongLong,
107/// A 32 bit floating point number
108Float,
109/// A 64 bit floating point number
110Double,
111/// A fixed point decimal value
112Numeric,
113/// A datatype to store a time value
114Time,
115/// A datatype to store a date value
116Date,
117/// A datatype containing timestamp values ranging from
118 /// '1000-01-01 00:00:00' to '9999-12-31 23:59:59'.
119DateTime,
120/// A datatype containing timestamp values ranging from
121 /// 1970-01-01 00:00:01' UTC to '2038-01-19 03:14:07' UTC.
122Timestamp,
123/// A datatype for string values
124String,
125/// A datatype containing binary large objects
126Blob,
127/// A value containing a set of bit's
128Bit,
129/// A user defined set type
130Set,
131/// A user defined enum type
132Enum,
133}
134135pub(crate) mod query_fragments {
136use crate::backend::sql_dialect::batch_update_support::SupportsBatchUpdate;
137use crate::backend::sql_dialect::on_conflict_clause::SupportsOnConflictClause;
138139#[derive(#[automatically_derived]impl ::core::fmt::Debug for
MysqlStyleDefaultValueClause {
#[inline]
#[rustc_trivial_field_reads]
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]
#[rustc_trivial_field_reads]
fn clone(&self) -> Self { *self }
}Clone, #[automatically_derived]impl ::core::marker::Copy for
MysqlStyleDefaultValueClause {
}Copy)]
140pub struct MysqlStyleDefaultValueClause;
141142#[derive(#[automatically_derived]impl ::core::fmt::Debug for MysqlConcatClause {
#[inline]
#[rustc_trivial_field_reads]
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]
#[rustc_trivial_field_reads]
fn clone(&self) -> Self { *self }
}Clone, #[automatically_derived]impl ::core::marker::Copy for MysqlConcatClause { }Copy)]
143pub struct MysqlConcatClause;
144145#[derive(#[automatically_derived]impl ::core::fmt::Debug for MysqlOnConflictClause {
#[inline]
#[rustc_trivial_field_reads]
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]
#[rustc_trivial_field_reads]
fn clone(&self) -> Self { *self }
}Clone, #[automatically_derived]impl ::core::marker::Copy for MysqlOnConflictClause {
}Copy)]
146pub struct MysqlOnConflictClause;
147148#[derive(#[automatically_derived]impl ::core::fmt::Debug for
MysqlRequiresOrderForWindowFunctions {
#[inline]
#[rustc_trivial_field_reads]
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]
#[rustc_trivial_field_reads]
fn clone(&self) -> Self { *self }
}Clone, #[automatically_derived]impl ::core::marker::Copy for
MysqlRequiresOrderForWindowFunctions {
}Copy)]
149pub struct MysqlRequiresOrderForWindowFunctions;
150151impl SupportsOnConflictClausefor MysqlOnConflictClause {}
152153#[derive(#[automatically_derived]impl ::core::fmt::Debug for
MySqlLikeBatchUpdateSupport {
#[inline]
#[rustc_trivial_field_reads]
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]
#[rustc_trivial_field_reads]
fn clone(&self) -> Self { *self }
}Clone, #[automatically_derived]impl ::core::marker::Copy for
MySqlLikeBatchUpdateSupport {
}Copy)]
154pub struct MySqlLikeBatchUpdateSupport;
155156impl SupportsBatchUpdatefor MySqlLikeBatchUpdateSupport {}
157}