Skip to main content

diesel/mysql_like/
mod.rs

1//! Provides shared types and functions related to working with MySQL and MariaDB
2
3#[cfg(any(feature = "mysql", feature = "mariadb"))]
4mod connection;
5mod types;
6
7pub(crate) mod query_builder;
8mod value;
9
10use core::hash::Hash;
11
12use 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;
17
18#[cfg(any(feature = "mysql", feature = "mariadb"))]
19pub use self::connection::MysqlLikeConnection;
20pub use self::value::{MysqlValue, NumericRepresentation};
21
22/// 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)]
28    pub use super::types::date_and_time::MysqlTime;
29    #[doc(inline)]
30    pub use super::types::date_and_time::MysqlTimestampType;
31}
32
33/// MySQL specific sql types
34pub mod sql_types {
35    #[doc(inline)]
36    pub use super::types::Datetime;
37    #[doc(inline)]
38    pub use super::types::Unsigned;
39}
40
41/// 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 MysqlLikeBackend
45where
46    Self: for<'a> Backend<
47            RawValue<'a> = MysqlValue<'a>,
48            BindCollector<'a> = RawBytesBindCollector<Self>,
49        >,
50    Self: TypeMetadata<TypeMetadata = MysqlType, MetadataLookup = ()>,
51    Self: Backend<QueryBuilder = MysqlLikeQueryBuilder<Self>>,
52    Self: Hash + Eq + Default,
53    Self: DieselReserveSpecialization,
54    Self: MapErrorNumber,
55    Self: 'static,
56{
57    #[doc(hidden)]
58    /// The scheme used in the connection URL for this backend.
59    /// "mysql" for MySQL, "mariadb" for MariaDB.
60    const SCHEME: &'static str;
61}
62
63pub(crate) trait MapErrorNumber {
64    /// Resolve the returned error number to a `DatabaseErrorKind`
65    fn map_error_number(error_number: u32) -> DatabaseErrorKind;
66}
67
68/// 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
74    Tiny,
75    /// A 8 bit unsigned integer
76    UnsignedTiny,
77    /// A 16 bit signed integer
78    Short,
79    /// A 16 bit unsigned integer
80    UnsignedShort,
81    /// A 32 bit signed integer
82    Long,
83    /// A 32 bit unsigned integer
84    UnsignedLong,
85    /// A 64 bit signed integer
86    LongLong,
87    /// A 64 bit unsigned integer
88    UnsignedLongLong,
89    /// A 32 bit floating point number
90    Float,
91    /// A 64 bit floating point number
92    Double,
93    /// A fixed point decimal value
94    Numeric,
95    /// A datatype to store a time value
96    Time,
97    /// A datatype to store a date value
98    Date,
99    /// A datatype containing timestamp values ranging from
100    /// '1000-01-01 00:00:00' to '9999-12-31 23:59:59'.
101    DateTime,
102    /// A datatype containing timestamp values ranging from
103    /// 1970-01-01 00:00:01' UTC to '2038-01-19 03:14:07' UTC.
104    Timestamp,
105    /// A datatype for string values
106    String,
107    /// A datatype containing binary large objects
108    Blob,
109    /// A value containing a set of bit's
110    Bit,
111    /// A user defined set type
112    Set,
113    /// A user defined enum type
114    Enum,
115}
116
117pub(crate) mod query_fragments {
118    use crate::backend::sql_dialect::batch_update_support::SupportsBatchUpdate;
119    use crate::backend::sql_dialect::on_conflict_clause::SupportsOnConflictClause;
120
121    #[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)]
122    pub struct MysqlStyleDefaultValueClause;
123
124    #[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)]
125    pub struct MysqlConcatClause;
126
127    #[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)]
128    pub struct MysqlOnConflictClause;
129
130    #[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)]
131    pub struct MysqlRequiresOrderForWindowFunctions;
132
133    impl SupportsOnConflictClause for MysqlOnConflictClause {}
134
135    #[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)]
136    pub struct MySqlLikeBatchUpdateSupport;
137
138    impl SupportsBatchUpdate for MySqlLikeBatchUpdateSupport {}
139}