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#[expect(private_bounds)]
44pub trait MysqlLikeBackend45where
46Self: for<'a> Backend<
47 RawValue<'a> = MysqlValue<'a>,
48 BindCollector<'a> = RawBytesBindCollector<Self>,
49 >,
50Self: TypeMetadata<TypeMetadata = MysqlType, MetadataLookup = ()>,
51Self: Backend<QueryBuilder = MysqlLikeQueryBuilder<Self>>,
52Self: Hash + Eq + Default,
53Self: DieselReserveSpecialization,
54Self: MapErrorNumber,
55Self: 'static,
56{
57#[doc(hidden)]
58/// The scheme used in the connection URL for this backend.
59 /// "mysql" for MySQL, "mariadb" for MariaDB.
60const SCHEME: &'static str;
61}
6263pub(crate) trait MapErrorNumber {
64/// Resolve the returned error number to a `DatabaseErrorKind`
65fn map_error_number(error_number: u32) -> DatabaseErrorKind;
66}
6768/// Represents possible types, that can be transmitted as via the
69/// Mysql wire protocol
70#[derive(#[automatically_derived]
impl ::core::fmt::Debug for MysqlType {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
static __NAMES: &str =
"TinyUnsignedTinyShortUnsignedShortLongUnsignedLongLongLongUnsignedLongLongFloatDoubleNumericTimeDateDateTimeTimestampStringBlobBitSetEnum";
static __OFFSET: [usize; 21] =
[0usize, 4usize, 16usize, 21usize, 34usize, 38usize, 50usize,
58usize, 74usize, 79usize, 85usize, 92usize, 96usize,
100usize, 108usize, 117usize, 123usize, 127usize, 130usize,
133usize, 137usize];
let __d = ::core::intrinsics::discriminant_value(self) as usize;
::core::fmt::Formatter::debug_c_like_enum_write_str(f, __NAMES,
&__OFFSET, __d)
}
}Debug, #[automatically_derived]
impl ::core::hash::Hash for MysqlType {
#[inline]
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
let __self_discr = ::core::intrinsics::discriminant_value(self);
::core::hash::Hash::hash(&__self_discr, state)
}
}Hash, #[automatically_derived]
impl ::core::cmp::PartialEq for MysqlType {
#[inline]
fn eq(&self, other: &MysqlType) -> bool {
let __self_discr = ::core::intrinsics::discriminant_value(self);
let __arg1_discr = ::core::intrinsics::discriminant_value(other);
__self_discr == __arg1_discr
}
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for MysqlType {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {}
}Eq, #[automatically_derived]
impl ::core::clone::Clone for MysqlType {
#[inline]
fn clone(&self) -> MysqlType { *self }
}Clone, #[automatically_derived]
impl ::core::marker::Copy for MysqlType { }Copy)]
71#[non_exhaustive]
72pub enum MysqlType {
73/// A 8 bit signed integer
74Tiny,
75/// A 8 bit unsigned integer
76UnsignedTiny,
77/// A 16 bit signed integer
78Short,
79/// A 16 bit unsigned integer
80UnsignedShort,
81/// A 32 bit signed integer
82Long,
83/// A 32 bit unsigned integer
84UnsignedLong,
85/// A 64 bit signed integer
86LongLong,
87/// A 64 bit unsigned integer
88UnsignedLongLong,
89/// A 32 bit floating point number
90Float,
91/// A 64 bit floating point number
92Double,
93/// A fixed point decimal value
94Numeric,
95/// A datatype to store a time value
96Time,
97/// A datatype to store a date value
98Date,
99/// A datatype containing timestamp values ranging from
100 /// '1000-01-01 00:00:00' to '9999-12-31 23:59:59'.
101DateTime,
102/// A datatype containing timestamp values ranging from
103 /// 1970-01-01 00:00:01' UTC to '2038-01-19 03:14:07' UTC.
104Timestamp,
105/// A datatype for string values
106String,
107/// A datatype containing binary large objects
108Blob,
109/// A value containing a set of bit's
110Bit,
111/// A user defined set type
112Set,
113/// A user defined enum type
114Enum,
115}
116117pub(crate) mod query_fragments {
118use crate::backend::sql_dialect::batch_update_support::SupportsBatchUpdate;
119use crate::backend::sql_dialect::on_conflict_clause::SupportsOnConflictClause;
120121#[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]
impl ::core::clone::Clone for MysqlStyleDefaultValueClause {
#[inline]
fn clone(&self) -> MysqlStyleDefaultValueClause { *self }
}Clone, #[automatically_derived]
impl ::core::marker::Copy for MysqlStyleDefaultValueClause { }Copy)]
122pub struct MysqlStyleDefaultValueClause;
123124#[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]
impl ::core::clone::Clone for MysqlConcatClause {
#[inline]
fn clone(&self) -> MysqlConcatClause { *self }
}Clone, #[automatically_derived]
impl ::core::marker::Copy for MysqlConcatClause { }Copy)]
125pub struct MysqlConcatClause;
126127#[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]
impl ::core::clone::Clone for MysqlOnConflictClause {
#[inline]
fn clone(&self) -> MysqlOnConflictClause { *self }
}Clone, #[automatically_derived]
impl ::core::marker::Copy for MysqlOnConflictClause { }Copy)]
128pub struct MysqlOnConflictClause;
129130#[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]
impl ::core::clone::Clone for MysqlRequiresOrderForWindowFunctions {
#[inline]
fn clone(&self) -> MysqlRequiresOrderForWindowFunctions { *self }
}Clone, #[automatically_derived]
impl ::core::marker::Copy for MysqlRequiresOrderForWindowFunctions { }Copy)]
131pub struct MysqlRequiresOrderForWindowFunctions;
132133impl SupportsOnConflictClausefor MysqlOnConflictClause {}
134135#[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]
impl ::core::clone::Clone for MySqlLikeBatchUpdateSupport {
#[inline]
fn clone(&self) -> MySqlLikeBatchUpdateSupport { *self }
}Clone, #[automatically_derived]
impl ::core::marker::Copy for MySqlLikeBatchUpdateSupport { }Copy)]
136pub struct MySqlLikeBatchUpdateSupport;
137138impl SupportsBatchUpdatefor MySqlLikeBatchUpdateSupport {}
139}