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#[doc(inline)]
22pub use sqlstate::mysql_like as sql_state;
23
24/// 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)]
30    pub use super::types::date_and_time::MysqlTime;
31    #[doc(inline)]
32    pub use super::types::date_and_time::MysqlTimestampType;
33}
34
35/// MySQL specific sql types
36pub mod sql_types {
37    #[doc(inline)]
38    pub use super::types::Datetime;
39    #[doc(inline)]
40    pub use super::types::Unsigned;
41}
42
43/// 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 MysqlLikeBackend
50where
51    Self: for<'a> Backend<
52            RawValue<'a> = MysqlValue<'a>,
53            BindCollector<'a> = RawBytesBindCollector<Self>,
54        >,
55    Self: TypeMetadata<TypeMetadata = MysqlType, MetadataLookup = ()>,
56    Self: Backend<QueryBuilder = MysqlLikeQueryBuilder<Self>>,
57    Self: Hash + Eq + Default,
58    Self: DieselReserveSpecialization,
59    Self: MapErrorNumber,
60    Self: 'static,
61{
62    #[doc(hidden)]
63    /// The scheme used in the connection URL for this backend.
64    /// "mysql" for MySQL, "mariadb" for MariaDB.
65    const SCHEME: &'static str;
66}
67
68#[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    )]
83    fn map_error_number(error_number: u32) -> DatabaseErrorKind;
84}
85
86/// 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
92    Tiny,
93    /// A 8 bit unsigned integer
94    UnsignedTiny,
95    /// A 16 bit signed integer
96    Short,
97    /// A 16 bit unsigned integer
98    UnsignedShort,
99    /// A 32 bit signed integer
100    Long,
101    /// A 32 bit unsigned integer
102    UnsignedLong,
103    /// A 64 bit signed integer
104    LongLong,
105    /// A 64 bit unsigned integer
106    UnsignedLongLong,
107    /// A 32 bit floating point number
108    Float,
109    /// A 64 bit floating point number
110    Double,
111    /// A fixed point decimal value
112    Numeric,
113    /// A datatype to store a time value
114    Time,
115    /// A datatype to store a date value
116    Date,
117    /// A datatype containing timestamp values ranging from
118    /// '1000-01-01 00:00:00' to '9999-12-31 23:59:59'.
119    DateTime,
120    /// A datatype containing timestamp values ranging from
121    /// 1970-01-01 00:00:01' UTC to '2038-01-19 03:14:07' UTC.
122    Timestamp,
123    /// A datatype for string values
124    String,
125    /// A datatype containing binary large objects
126    Blob,
127    /// A value containing a set of bit's
128    Bit,
129    /// A user defined set type
130    Set,
131    /// A user defined enum type
132    Enum,
133}
134
135pub(crate) mod query_fragments {
136    use crate::backend::sql_dialect::batch_update_support::SupportsBatchUpdate;
137    use crate::backend::sql_dialect::on_conflict_clause::SupportsOnConflictClause;
138
139    #[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)]
140    pub struct MysqlStyleDefaultValueClause;
141
142    #[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)]
143    pub struct MysqlConcatClause;
144
145    #[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)]
146    pub struct MysqlOnConflictClause;
147
148    #[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)]
149    pub struct MysqlRequiresOrderForWindowFunctions;
150
151    impl SupportsOnConflictClause for MysqlOnConflictClause {}
152
153    #[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)]
154    pub struct MySqlLikeBatchUpdateSupport;
155
156    impl SupportsBatchUpdate for MySqlLikeBatchUpdateSupport {}
157}