Skip to main content

diesel/collation/
mod.rs

1//! This module contains types that represent SQL collations.
2//!
3//! These types are used as arguments for
4//! [`TextExpressionMethods::collate`](crate::expression_methods::TextExpressionMethods::collate).
5
6use crate::backend::Backend;
7use crate::query_builder::{AstPass, QueryFragment, QueryId};
8use crate::result::QueryResult;
9
10/// Trait to identify a valid collation.
11pub trait Collation: QueryId + Clone + Send + Sync + 'static {}
12
13/// A custom collation.
14///
15/// This type wraps a string that represents a collation name.
16/// It can be used to use a collation that is not supported by Diesel.
17#[derive(#[automatically_derived]
impl ::core::fmt::Debug for Custom {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::debug_tuple_field1_finish(f, "Custom",
            &&self.0)
    }
}Debug, #[automatically_derived]
impl ::core::clone::Clone for Custom {
    #[inline]
    fn clone(&self) -> Custom {
        let _: ::core::clone::AssertParamIsClone<&'static str>;
        *self
    }
}Clone, #[automatically_derived]
impl ::core::marker::Copy for Custom { }Copy, #[automatically_derived]
impl ::core::cmp::PartialEq for Custom {
    #[inline]
    fn eq(&self, other: &Custom) -> bool { self.0 == other.0 }
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for Custom {
    #[inline]
    #[doc(hidden)]
    #[coverage(off)]
    fn assert_receiver_is_total_eq(&self) {
        let _: ::core::cmp::AssertParamIsEq<&'static str>;
    }
}Eq, #[automatically_derived]
impl ::core::hash::Hash for Custom {
    #[inline]
    fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
        ::core::hash::Hash::hash(&self.0, state)
    }
}Hash)]
18pub struct Custom(pub &'static str);
19
20impl Collation for Custom {}
21
22impl<DB: Backend> QueryFragment<DB> for Custom {
23    fn walk_ast<'b>(&'b self, mut out: AstPass<'_, 'b, DB>) -> QueryResult<()> {
24        out.push_sql(self.0);
25        Ok(())
26    }
27}
28
29impl QueryId for Custom {
30    type QueryId = ();
31    const HAS_STATIC_QUERY_ID: bool = false;
32}
33
34/// The `BINARY` collation.
35///
36/// This collation is binary, case-sensitive, and locale-free.
37/// It is supported by SQLite.
38#[derive(#[automatically_derived]
impl ::core::fmt::Debug for Binary {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::write_str(f, "Binary")
    }
}Debug, #[automatically_derived]
impl ::core::clone::Clone for Binary {
    #[inline]
    fn clone(&self) -> Binary { *self }
}Clone, #[automatically_derived]
impl ::core::marker::Copy for Binary { }Copy, #[automatically_derived]
impl ::core::cmp::PartialEq for Binary {
    #[inline]
    fn eq(&self, other: &Binary) -> bool { true }
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for Binary {
    #[inline]
    #[doc(hidden)]
    #[coverage(off)]
    fn assert_receiver_is_total_eq(&self) {}
}Eq, #[automatically_derived]
impl ::core::hash::Hash for Binary {
    #[inline]
    fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {}
}Hash, #[automatically_derived]
impl ::core::default::Default for Binary {
    #[inline]
    fn default() -> Binary { Binary {} }
}Default, const _: () =
    {
        use diesel;
        #[allow(non_camel_case_types)]
        impl diesel::query_builder::QueryId for Binary {
            type QueryId = Binary<>;
            const HAS_STATIC_QUERY_ID: bool = true;
            const IS_WINDOW_FUNCTION: bool = false;
        }
    };QueryId)]
39#[cfg(feature = "__sqlite-shared")]
40pub struct Binary;
41
42#[cfg(feature = "__sqlite-shared")]
43impl Collation for Binary {}
44
45#[cfg(feature = "__sqlite-shared")]
46impl QueryFragment<crate::sqlite::Sqlite> for Binary {
47    fn walk_ast<'b>(&'b self, mut out: AstPass<'_, 'b, crate::sqlite::Sqlite>) -> QueryResult<()> {
48        out.push_sql("BINARY");
49        Ok(())
50    }
51}
52
53/// The `C` collation.
54///
55/// This collation is byte-wise, with only ASCII A-Z treated as letters.
56/// It is supported by PostgreSQL.
57#[derive(#[automatically_derived]
impl ::core::fmt::Debug for C {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::write_str(f, "C")
    }
}Debug, #[automatically_derived]
impl ::core::clone::Clone for C {
    #[inline]
    fn clone(&self) -> C { *self }
}Clone, #[automatically_derived]
impl ::core::marker::Copy for C { }Copy, #[automatically_derived]
impl ::core::cmp::PartialEq for C {
    #[inline]
    fn eq(&self, other: &C) -> bool { true }
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for C {
    #[inline]
    #[doc(hidden)]
    #[coverage(off)]
    fn assert_receiver_is_total_eq(&self) {}
}Eq, #[automatically_derived]
impl ::core::hash::Hash for C {
    #[inline]
    fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {}
}Hash, #[automatically_derived]
impl ::core::default::Default for C {
    #[inline]
    fn default() -> C { C {} }
}Default, const _: () =
    {
        use diesel;
        #[allow(non_camel_case_types)]
        impl diesel::query_builder::QueryId for C {
            type QueryId = C<>;
            const HAS_STATIC_QUERY_ID: bool = true;
            const IS_WINDOW_FUNCTION: bool = false;
        }
    };QueryId)]
58#[cfg(feature = "postgres_backend")]
59pub struct C;
60
61#[cfg(feature = "postgres_backend")]
62impl Collation for C {}
63
64#[cfg(feature = "postgres_backend")]
65impl QueryFragment<crate::pg::Pg> for C {
66    fn walk_ast<'b>(&'b self, mut out: AstPass<'_, 'b, crate::pg::Pg>) -> QueryResult<()> {
67        out.push_sql("\"C\"");
68        Ok(())
69    }
70}
71
72/// The `NOCASE` collation.
73///
74/// This collation is ASCII-only case-insensitive.
75/// It is supported by SQLite.
76#[derive(#[automatically_derived]
impl ::core::fmt::Debug for NoCase {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::write_str(f, "NoCase")
    }
}Debug, #[automatically_derived]
impl ::core::clone::Clone for NoCase {
    #[inline]
    fn clone(&self) -> NoCase { *self }
}Clone, #[automatically_derived]
impl ::core::marker::Copy for NoCase { }Copy, #[automatically_derived]
impl ::core::cmp::PartialEq for NoCase {
    #[inline]
    fn eq(&self, other: &NoCase) -> bool { true }
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for NoCase {
    #[inline]
    #[doc(hidden)]
    #[coverage(off)]
    fn assert_receiver_is_total_eq(&self) {}
}Eq, #[automatically_derived]
impl ::core::hash::Hash for NoCase {
    #[inline]
    fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {}
}Hash, #[automatically_derived]
impl ::core::default::Default for NoCase {
    #[inline]
    fn default() -> NoCase { NoCase {} }
}Default, const _: () =
    {
        use diesel;
        #[allow(non_camel_case_types)]
        impl diesel::query_builder::QueryId for NoCase {
            type QueryId = NoCase<>;
            const HAS_STATIC_QUERY_ID: bool = true;
            const IS_WINDOW_FUNCTION: bool = false;
        }
    };QueryId)]
77#[cfg(feature = "__sqlite-shared")]
78pub struct NoCase;
79
80#[cfg(feature = "__sqlite-shared")]
81impl Collation for NoCase {}
82
83#[cfg(feature = "__sqlite-shared")]
84impl QueryFragment<crate::sqlite::Sqlite> for NoCase {
85    fn walk_ast<'b>(&'b self, mut out: AstPass<'_, 'b, crate::sqlite::Sqlite>) -> QueryResult<()> {
86        out.push_sql("NOCASE");
87        Ok(())
88    }
89}
90
91/// The `POSIX` collation.
92///
93/// This collation is byte-wise, with only ASCII A-Z treated as letters.
94/// It is supported by PostgreSQL.
95#[derive(#[automatically_derived]
impl ::core::fmt::Debug for Posix {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::write_str(f, "Posix")
    }
}Debug, #[automatically_derived]
impl ::core::clone::Clone for Posix {
    #[inline]
    fn clone(&self) -> Posix { *self }
}Clone, #[automatically_derived]
impl ::core::marker::Copy for Posix { }Copy, #[automatically_derived]
impl ::core::cmp::PartialEq for Posix {
    #[inline]
    fn eq(&self, other: &Posix) -> bool { true }
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for Posix {
    #[inline]
    #[doc(hidden)]
    #[coverage(off)]
    fn assert_receiver_is_total_eq(&self) {}
}Eq, #[automatically_derived]
impl ::core::hash::Hash for Posix {
    #[inline]
    fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {}
}Hash, #[automatically_derived]
impl ::core::default::Default for Posix {
    #[inline]
    fn default() -> Posix { Posix {} }
}Default, const _: () =
    {
        use diesel;
        #[allow(non_camel_case_types)]
        impl diesel::query_builder::QueryId for Posix {
            type QueryId = Posix<>;
            const HAS_STATIC_QUERY_ID: bool = true;
            const IS_WINDOW_FUNCTION: bool = false;
        }
    };QueryId)]
96#[cfg(feature = "postgres_backend")]
97pub struct Posix;
98
99#[cfg(feature = "postgres_backend")]
100impl Collation for Posix {}
101
102#[cfg(feature = "postgres_backend")]
103impl QueryFragment<crate::pg::Pg> for Posix {
104    fn walk_ast<'b>(&'b self, mut out: AstPass<'_, 'b, crate::pg::Pg>) -> QueryResult<()> {
105        out.push_sql("\"POSIX\"");
106        Ok(())
107    }
108}
109
110/// The `RTRIM` collation.
111///
112/// This collation ignores trailing spaces.
113/// It is supported by SQLite.
114#[derive(#[automatically_derived]
impl ::core::fmt::Debug for RTrim {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::write_str(f, "RTrim")
    }
}Debug, #[automatically_derived]
impl ::core::clone::Clone for RTrim {
    #[inline]
    fn clone(&self) -> RTrim { *self }
}Clone, #[automatically_derived]
impl ::core::marker::Copy for RTrim { }Copy, #[automatically_derived]
impl ::core::cmp::PartialEq for RTrim {
    #[inline]
    fn eq(&self, other: &RTrim) -> bool { true }
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for RTrim {
    #[inline]
    #[doc(hidden)]
    #[coverage(off)]
    fn assert_receiver_is_total_eq(&self) {}
}Eq, #[automatically_derived]
impl ::core::hash::Hash for RTrim {
    #[inline]
    fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {}
}Hash, #[automatically_derived]
impl ::core::default::Default for RTrim {
    #[inline]
    fn default() -> RTrim { RTrim {} }
}Default, const _: () =
    {
        use diesel;
        #[allow(non_camel_case_types)]
        impl diesel::query_builder::QueryId for RTrim {
            type QueryId = RTrim<>;
            const HAS_STATIC_QUERY_ID: bool = true;
            const IS_WINDOW_FUNCTION: bool = false;
        }
    };QueryId)]
115#[cfg(feature = "__sqlite-shared")]
116pub struct RTrim;
117
118#[cfg(feature = "__sqlite-shared")]
119impl Collation for RTrim {}
120
121#[cfg(feature = "__sqlite-shared")]
122impl QueryFragment<crate::sqlite::Sqlite> for RTrim {
123    fn walk_ast<'b>(&'b self, mut out: AstPass<'_, 'b, crate::sqlite::Sqlite>) -> QueryResult<()> {
124        out.push_sql("RTRIM");
125        Ok(())
126    }
127}