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`
65// Bound on `MysqlLikeBackend` everywhere, called only by the connections.
66#[cfg_attr(
67 not(any(feature = "mysql", feature = "mariadb")),
68 expect(dead_code, reason = "only the connections call it")
69 )]
70fn map_error_number(error_number: u32) -> DatabaseErrorKind;
71}
7273/// Represents possible types, that can be transmitted as via the
74/// Mysql wire protocol
75#[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::marker::StructuralPartialEq for MysqlType { }
#[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]
#[doc(hidden)]
unsafe impl ::core::clone::TrivialClone for MysqlType { }
#[automatically_derived]
impl ::core::clone::Clone for MysqlType {
#[inline]
fn clone(&self) -> MysqlType { *self }
}Clone, #[automatically_derived]
impl ::core::marker::Copy for MysqlType { }Copy)]
76#[non_exhaustive]
77pub enum MysqlType {
78/// A 8 bit signed integer
79Tiny,
80/// A 8 bit unsigned integer
81UnsignedTiny,
82/// A 16 bit signed integer
83Short,
84/// A 16 bit unsigned integer
85UnsignedShort,
86/// A 32 bit signed integer
87Long,
88/// A 32 bit unsigned integer
89UnsignedLong,
90/// A 64 bit signed integer
91LongLong,
92/// A 64 bit unsigned integer
93UnsignedLongLong,
94/// A 32 bit floating point number
95Float,
96/// A 64 bit floating point number
97Double,
98/// A fixed point decimal value
99Numeric,
100/// A datatype to store a time value
101Time,
102/// A datatype to store a date value
103Date,
104/// A datatype containing timestamp values ranging from
105 /// '1000-01-01 00:00:00' to '9999-12-31 23:59:59'.
106DateTime,
107/// A datatype containing timestamp values ranging from
108 /// 1970-01-01 00:00:01' UTC to '2038-01-19 03:14:07' UTC.
109Timestamp,
110/// A datatype for string values
111String,
112/// A datatype containing binary large objects
113Blob,
114/// A value containing a set of bit's
115Bit,
116/// A user defined set type
117Set,
118/// A user defined enum type
119Enum,
120}
121122pub(crate) mod query_fragments {
123use crate::backend::sql_dialect::batch_update_support::SupportsBatchUpdate;
124use crate::backend::sql_dialect::on_conflict_clause::SupportsOnConflictClause;
125126#[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) -> MysqlStyleDefaultValueClause { *self }
}Clone, #[automatically_derived]
impl ::core::marker::Copy for MysqlStyleDefaultValueClause { }Copy)]
127pub struct MysqlStyleDefaultValueClause;
128129#[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) -> MysqlConcatClause { *self }
}Clone, #[automatically_derived]
impl ::core::marker::Copy for MysqlConcatClause { }Copy)]
130pub struct MysqlConcatClause;
131132#[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) -> MysqlOnConflictClause { *self }
}Clone, #[automatically_derived]
impl ::core::marker::Copy for MysqlOnConflictClause { }Copy)]
133pub struct MysqlOnConflictClause;
134135#[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) -> MysqlRequiresOrderForWindowFunctions { *self }
}Clone, #[automatically_derived]
impl ::core::marker::Copy for MysqlRequiresOrderForWindowFunctions { }Copy)]
136pub struct MysqlRequiresOrderForWindowFunctions;
137138impl SupportsOnConflictClausefor MysqlOnConflictClause {}
139140#[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) -> MySqlLikeBatchUpdateSupport { *self }
}Clone, #[automatically_derived]
impl ::core::marker::Copy for MySqlLikeBatchUpdateSupport { }Copy)]
141pub struct MySqlLikeBatchUpdateSupport;
142143impl SupportsBatchUpdatefor MySqlLikeBatchUpdateSupport {}
144}