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#[cfg_attr(
44    not(feature = "i-implement-a-third-party-backend-and-opt-into-breaking-changes"),
45    expect(private_bounds)
46)]
47pub trait MysqlLikeBackend
48where
49    Self: for<'a> Backend<
50            RawValue<'a> = MysqlValue<'a>,
51            BindCollector<'a> = RawBytesBindCollector<Self>,
52        >,
53    Self: TypeMetadata<TypeMetadata = MysqlType, MetadataLookup = ()>,
54    Self: Backend<QueryBuilder = MysqlLikeQueryBuilder<Self>>,
55    Self: Hash + Eq + Default,
56    Self: DieselReserveSpecialization,
57    Self: MapErrorNumber,
58    Self: 'static,
59{
60    #[doc(hidden)]
61    /// The scheme used in the connection URL for this backend.
62    /// "mysql" for MySQL, "mariadb" for MariaDB.
63    const SCHEME: &'static str;
64}
65
66pub 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    )]
80    fn map_error_number(error_number: u32) -> DatabaseErrorKind;
81}
82
83/// 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::write_str(f,
            match self {
                MysqlType::Tiny => "Tiny",
                MysqlType::UnsignedTiny => "UnsignedTiny",
                MysqlType::Short => "Short",
                MysqlType::UnsignedShort => "UnsignedShort",
                MysqlType::Long => "Long",
                MysqlType::UnsignedLong => "UnsignedLong",
                MysqlType::LongLong => "LongLong",
                MysqlType::UnsignedLongLong => "UnsignedLongLong",
                MysqlType::Float => "Float",
                MysqlType::Double => "Double",
                MysqlType::Numeric => "Numeric",
                MysqlType::Time => "Time",
                MysqlType::Date => "Date",
                MysqlType::DateTime => "DateTime",
                MysqlType::Timestamp => "Timestamp",
                MysqlType::String => "String",
                MysqlType::Blob => "Blob",
                MysqlType::Bit => "Bit",
                MysqlType::Set => "Set",
                MysqlType::Enum => "Enum",
            })
    }
}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
89    Tiny,
90    /// A 8 bit unsigned integer
91    UnsignedTiny,
92    /// A 16 bit signed integer
93    Short,
94    /// A 16 bit unsigned integer
95    UnsignedShort,
96    /// A 32 bit signed integer
97    Long,
98    /// A 32 bit unsigned integer
99    UnsignedLong,
100    /// A 64 bit signed integer
101    LongLong,
102    /// A 64 bit unsigned integer
103    UnsignedLongLong,
104    /// A 32 bit floating point number
105    Float,
106    /// A 64 bit floating point number
107    Double,
108    /// A fixed point decimal value
109    Numeric,
110    /// A datatype to store a time value
111    Time,
112    /// A datatype to store a date value
113    Date,
114    /// A datatype containing timestamp values ranging from
115    /// '1000-01-01 00:00:00' to '9999-12-31 23:59:59'.
116    DateTime,
117    /// A datatype containing timestamp values ranging from
118    /// 1970-01-01 00:00:01' UTC to '2038-01-19 03:14:07' UTC.
119    Timestamp,
120    /// A datatype for string values
121    String,
122    /// A datatype containing binary large objects
123    Blob,
124    /// A value containing a set of bit's
125    Bit,
126    /// A user defined set type
127    Set,
128    /// A user defined enum type
129    Enum,
130}
131
132pub(crate) mod query_fragments {
133    use crate::backend::sql_dialect::batch_update_support::SupportsBatchUpdate;
134    use crate::backend::sql_dialect::on_conflict_clause::SupportsOnConflictClause;
135
136    #[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)]
137    pub struct MysqlStyleDefaultValueClause;
138
139    #[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)]
140    pub struct MysqlConcatClause;
141
142    #[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)]
143    pub struct MysqlOnConflictClause;
144
145    #[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)]
146    pub struct MysqlRequiresOrderForWindowFunctions;
147
148    impl SupportsOnConflictClause for MysqlOnConflictClause {}
149
150    #[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)]
151    pub struct MySqlLikeBatchUpdateSupport;
152
153    impl SupportsBatchUpdate for MySqlLikeBatchUpdateSupport {}
154}