Skip to main content

diesel/mariadb/
backend.rs

1use crate::backend::{
2    Backend, DieselReserveSpecialization, SqlDialect, TrustedBackend, sql_dialect,
3};
4use crate::mariadb::{MariadbQueryBuilder, MariadbValue};
5use crate::mysql_like::query_fragments::MySqlLikeBatchUpdateSupport;
6use crate::mysql_like::{MapErrorNumber, MysqlLikeBackend};
7use crate::query_builder::bind_collector::RawBytesBindCollector;
8use crate::result::DatabaseErrorKind;
9use crate::sql_types::TypeMetadata;
10
11/// The MariaDB backend
12#[derive(#[automatically_derived]
impl ::core::fmt::Debug for Mariadb {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::write_str(f, "Mariadb")
    }
}Debug, #[automatically_derived]
impl ::core::marker::Copy for Mariadb { }Copy, #[automatically_derived]
impl ::core::clone::Clone for Mariadb {
    #[inline]
    fn clone(&self) -> Mariadb { *self }
}Clone, #[automatically_derived]
impl ::core::hash::Hash for Mariadb {
    #[inline]
    fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {}
}Hash, #[automatically_derived]
impl ::core::cmp::PartialEq for Mariadb {
    #[inline]
    fn eq(&self, other: &Mariadb) -> bool { true }
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for Mariadb {
    #[inline]
    #[doc(hidden)]
    #[coverage(off)]
    fn assert_fields_are_eq(&self) {}
}Eq, #[automatically_derived]
impl ::core::default::Default for Mariadb {
    #[inline]
    fn default() -> Mariadb { Mariadb {} }
}Default)]
13pub struct Mariadb;
14
15/// Represents possible types, that can be transmitted as via the
16/// Mysql wire protocol
17pub type MariadbType = crate::mysql_like::MysqlType;
18
19impl Backend for Mariadb {
20    type QueryBuilder = MariadbQueryBuilder;
21    type RawValue<'a> = MariadbValue<'a>;
22    type BindCollector<'a> = RawBytesBindCollector<Self>;
23}
24
25impl TypeMetadata for Mariadb {
26    type TypeMetadata = MariadbType;
27
28    type MetadataLookup = ();
29}
30
31impl SqlDialect for Mariadb {
32    type ReturningClause = sql_dialect::returning_clause::DoesNotSupportReturningClause;
33
34    type OnConflictClause = MariadbOnConflictClause;
35
36    type InsertWithDefaultKeyword = sql_dialect::default_keyword_for_insert::IsoSqlDefaultKeyword;
37    type BatchInsertSupport = sql_dialect::batch_insert_support::PostgresLikeBatchInsertSupport;
38    type DefaultValueClauseForInsert = MariadbStyleDefaultValueClause;
39
40    type BatchUpdateSupport = MySqlLikeBatchUpdateSupport;
41
42    type EmptyFromClauseSyntax = sql_dialect::from_clause_syntax::AnsiSqlFromClauseSyntax;
43    type SelectStatementSyntax = sql_dialect::select_statement_syntax::AnsiSqlSelectStatement;
44
45    type ExistsSyntax = sql_dialect::exists_syntax::AnsiSqlExistsSyntax;
46    type ArrayComparison = sql_dialect::array_comparison::AnsiSqlArrayComparison;
47
48    type ConcatClause = MariadbConcatClause;
49    type AliasSyntax = sql_dialect::alias_syntax::AsAliasSyntax;
50
51    type WindowFrameClauseGroupSupport =
52        sql_dialect::window_frame_clause_group_support::NoGroupWindowFrameUnit;
53
54    type WindowFrameExclusionSupport =
55        sql_dialect::window_frame_exclusion_support::NoFrameFrameExclusionSupport;
56
57    type AggregateFunctionExpressions =
58        sql_dialect::aggregate_function_expressions::NoAggregateFunctionExpressions;
59
60    type BuiltInWindowFunctionRequireOrder = MariadbRequiresOrderForWindowFunctions;
61}
62
63impl DieselReserveSpecialization for Mariadb {}
64impl TrustedBackend for Mariadb {}
65
66pub(crate) type MariadbOnConflictClause = crate::mysql_like::query_fragments::MysqlOnConflictClause;
67pub(crate) type MariadbStyleDefaultValueClause =
68    crate::mysql_like::query_fragments::MysqlStyleDefaultValueClause;
69pub(crate) type MariadbConcatClause = crate::mysql_like::query_fragments::MysqlConcatClause;
70pub(crate) type MariadbRequiresOrderForWindowFunctions =
71    crate::mysql_like::query_fragments::MysqlRequiresOrderForWindowFunctions;
72
73impl MysqlLikeBackend for Mariadb {
74    const SCHEME: &'static str = "mariadb";
75}
76
77impl MapErrorNumber for Mariadb {
78    fn map_error_number(error_number: u32) -> crate::result::DatabaseErrorKind {
79        // These values are not exposed by the C API, but are documented
80        // at https://mariadb.com/docs/server/reference/error-codes/mariadb-error-code-reference
81        match error_number {
82            1022 | 1062 | 1586 | 1859 => DatabaseErrorKind::UniqueViolation,
83            1216 | 1217 | 1451 | 1557 | 1452 | 1830 | 1834 => {
84                DatabaseErrorKind::ForeignKeyViolation
85            }
86            1792 => DatabaseErrorKind::ReadOnlyTransaction,
87            1048 | 1364 => DatabaseErrorKind::NotNullViolation,
88            4025 => DatabaseErrorKind::CheckViolation,
89            1213 => DatabaseErrorKind::SerializationFailure,
90            _ => DatabaseErrorKind::Unknown,
91        }
92    }
93}