Skip to main content

diesel/sql_types/
mod.rs

1//! Types which represent a SQL data type.
2//!
3//! The structs in this module are *only* used as markers to represent a SQL type.
4//! They should never be used in your structs.
5//! If you'd like to know the rust types which can be used for a given SQL type,
6//! see the documentation for that SQL type.
7//! Additional types may be provided by other crates.
8//!
9//! To see which SQL type can be used with a given Rust type,
10//! see the "Implementors" section of [`FromSql`].
11//!
12//! [`FromSql`]: super::deserialize::FromSql
13//!
14//! Any backend specific types are re-exported through this module
15
16mod fold;
17pub mod ops;
18mod ord;
19
20pub use self::fold::Foldable;
21pub use self::ord::SqlOrd;
22
23use crate::backend::Backend;
24use crate::expression::TypedExpressionType;
25use crate::query_builder::QueryId;
26
27/// The boolean SQL type.
28///
29/// On backends without a native boolean type,
30/// this is emulated with the smallest supported integer.
31///
32/// ### [`ToSql`](crate::serialize::ToSql) impls
33///
34/// - [`bool`][bool]
35///
36/// ### [`FromSql`](crate::deserialize::FromSql) impls
37///
38/// - [`bool`][bool]
39///
40/// [bool]: https://doc.rust-lang.org/nightly/std/primitive.bool.html
41#[derive(#[automatically_derived]
impl ::core::fmt::Debug for Bool {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::write_str(f, "Bool")
    }
}Debug, #[automatically_derived]
impl ::core::clone::Clone for Bool {
    #[inline]
    fn clone(&self) -> Bool { *self }
}Clone, #[automatically_derived]
impl ::core::marker::Copy for Bool { }Copy, #[automatically_derived]
impl ::core::default::Default for Bool {
    #[inline]
    fn default() -> Bool { Bool {} }
}Default, const _: () =
    {
        use diesel;
        #[allow(non_camel_case_types)]
        impl diesel::query_builder::QueryId for Bool {
            type QueryId = Bool<>;
            const HAS_STATIC_QUERY_ID: bool = true;
            const IS_WINDOW_FUNCTION: bool = false;
        }
    };QueryId, const _: () =
    {
        use diesel;
        impl diesel::sql_types::SqlType for Bool {
            type IsNull = diesel::sql_types::is_nullable::NotNull;
            const IS_ARRAY: bool = false;
        }
        impl diesel::sql_types::SingleValue for Bool {}
        impl diesel::sql_types::HasSqlType<Bool> for diesel::sqlite::Sqlite {
            fn metadata(_: &mut ()) -> diesel::sqlite::SqliteType {
                diesel::sqlite::SqliteType::Integer
            }
        }
        impl diesel::sql_types::HasSqlType<Bool> for diesel::mysql::Mysql {
            fn metadata(_: &mut ()) -> diesel::mysql::MysqlType {
                diesel::mysql::MysqlType::Tiny
            }
        }
        impl diesel::sql_types::HasSqlType<Bool> for diesel::pg::Pg {
            fn metadata(_: &mut Self::MetadataLookup)
                -> diesel::pg::PgTypeMetadata {
                diesel::pg::PgTypeMetadata::new(16, 1000)
            }
        }
    };SqlType)]
42#[diesel(postgres_type(oid = 16, array_oid = 1000))]
43#[diesel(sqlite_type(name = "Integer"))]
44#[diesel(mysql_type(name = "Tiny"))]
45pub struct Bool;
46
47/// The tiny integer SQL type.
48///
49/// This is only available on MySQL.
50/// Keep in mind that `diesel print-schema` will see `TINYINT(1)` as `Bool`,
51/// not `TinyInt`.
52///
53/// ### [`ToSql`](crate::serialize::ToSql) impls
54///
55/// - [`i8`][i8]
56///
57/// ### [`FromSql`](crate::deserialize::FromSql) impls
58///
59/// - [`i8`][i8]
60///
61/// [i8]: https://doc.rust-lang.org/nightly/std/primitive.i8.html
62#[derive(#[automatically_derived]
impl ::core::fmt::Debug for TinyInt {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::write_str(f, "TinyInt")
    }
}Debug, #[automatically_derived]
impl ::core::clone::Clone for TinyInt {
    #[inline]
    fn clone(&self) -> TinyInt { *self }
}Clone, #[automatically_derived]
impl ::core::marker::Copy for TinyInt { }Copy, #[automatically_derived]
impl ::core::default::Default for TinyInt {
    #[inline]
    fn default() -> TinyInt { TinyInt {} }
}Default, const _: () =
    {
        use diesel;
        #[allow(non_camel_case_types)]
        impl diesel::query_builder::QueryId for TinyInt {
            type QueryId = TinyInt<>;
            const HAS_STATIC_QUERY_ID: bool = true;
            const IS_WINDOW_FUNCTION: bool = false;
        }
    };QueryId, const _: () =
    {
        use diesel;
        impl diesel::sql_types::SqlType for TinyInt {
            type IsNull = diesel::sql_types::is_nullable::NotNull;
            const IS_ARRAY: bool = false;
        }
        impl diesel::sql_types::SingleValue for TinyInt {}
        impl diesel::sql_types::HasSqlType<TinyInt> for diesel::mysql::Mysql {
            fn metadata(_: &mut ()) -> diesel::mysql::MysqlType {
                diesel::mysql::MysqlType::Tiny
            }
        }
    };SqlType)]
63#[diesel(mysql_type(name = "Tiny"))]
64pub struct TinyInt;
65#[doc(hidden)]
66pub type Tinyint = TinyInt;
67
68/// The small integer SQL type.
69///
70/// ### [`ToSql`](crate::serialize::ToSql) impls
71///
72/// - [`i16`][i16]
73///
74/// ### [`FromSql`](crate::deserialize::FromSql) impls
75///
76/// - [`i16`][i16]
77///
78/// [i16]: https://doc.rust-lang.org/nightly/std/primitive.i16.html
79#[derive(#[automatically_derived]
impl ::core::fmt::Debug for SmallInt {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::write_str(f, "SmallInt")
    }
}Debug, #[automatically_derived]
impl ::core::clone::Clone for SmallInt {
    #[inline]
    fn clone(&self) -> SmallInt { *self }
}Clone, #[automatically_derived]
impl ::core::marker::Copy for SmallInt { }Copy, #[automatically_derived]
impl ::core::default::Default for SmallInt {
    #[inline]
    fn default() -> SmallInt { SmallInt {} }
}Default, const _: () =
    {
        use diesel;
        #[allow(non_camel_case_types)]
        impl diesel::query_builder::QueryId for SmallInt {
            type QueryId = SmallInt<>;
            const HAS_STATIC_QUERY_ID: bool = true;
            const IS_WINDOW_FUNCTION: bool = false;
        }
    };QueryId, const _: () =
    {
        use diesel;
        impl diesel::sql_types::SqlType for SmallInt {
            type IsNull = diesel::sql_types::is_nullable::NotNull;
            const IS_ARRAY: bool = false;
        }
        impl diesel::sql_types::SingleValue for SmallInt {}
        impl diesel::sql_types::HasSqlType<SmallInt> for
            diesel::sqlite::Sqlite {
            fn metadata(_: &mut ()) -> diesel::sqlite::SqliteType {
                diesel::sqlite::SqliteType::SmallInt
            }
        }
        impl diesel::sql_types::HasSqlType<SmallInt> for diesel::mysql::Mysql
            {
            fn metadata(_: &mut ()) -> diesel::mysql::MysqlType {
                diesel::mysql::MysqlType::Short
            }
        }
        impl diesel::sql_types::HasSqlType<SmallInt> for diesel::pg::Pg {
            fn metadata(_: &mut Self::MetadataLookup)
                -> diesel::pg::PgTypeMetadata {
                diesel::pg::PgTypeMetadata::new(21, 1005)
            }
        }
    };SqlType)]
80#[diesel(postgres_type(oid = 21, array_oid = 1005))]
81#[diesel(sqlite_type(name = "SmallInt"))]
82#[diesel(mysql_type(name = "Short"))]
83pub struct SmallInt;
84#[doc(hidden)]
85pub type Int2 = SmallInt;
86#[doc(hidden)]
87pub type Smallint = SmallInt;
88
89/// The integer SQL type.
90///
91/// ### [`ToSql`](crate::serialize::ToSql) impls
92///
93/// - [`i32`][i32]
94///
95/// ### [`FromSql`](crate::deserialize::FromSql) impls
96///
97/// - [`i32`][i32]
98///
99/// [i32]: https://doc.rust-lang.org/nightly/std/primitive.i32.html
100#[derive(#[automatically_derived]
impl ::core::fmt::Debug for Integer {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::write_str(f, "Integer")
    }
}Debug, #[automatically_derived]
impl ::core::clone::Clone for Integer {
    #[inline]
    fn clone(&self) -> Integer { *self }
}Clone, #[automatically_derived]
impl ::core::marker::Copy for Integer { }Copy, #[automatically_derived]
impl ::core::default::Default for Integer {
    #[inline]
    fn default() -> Integer { Integer {} }
}Default, const _: () =
    {
        use diesel;
        #[allow(non_camel_case_types)]
        impl diesel::query_builder::QueryId for Integer {
            type QueryId = Integer<>;
            const HAS_STATIC_QUERY_ID: bool = true;
            const IS_WINDOW_FUNCTION: bool = false;
        }
    };QueryId, const _: () =
    {
        use diesel;
        impl diesel::sql_types::SqlType for Integer {
            type IsNull = diesel::sql_types::is_nullable::NotNull;
            const IS_ARRAY: bool = false;
        }
        impl diesel::sql_types::SingleValue for Integer {}
        impl diesel::sql_types::HasSqlType<Integer> for diesel::sqlite::Sqlite
            {
            fn metadata(_: &mut ()) -> diesel::sqlite::SqliteType {
                diesel::sqlite::SqliteType::Integer
            }
        }
        impl diesel::sql_types::HasSqlType<Integer> for diesel::mysql::Mysql {
            fn metadata(_: &mut ()) -> diesel::mysql::MysqlType {
                diesel::mysql::MysqlType::Long
            }
        }
        impl diesel::sql_types::HasSqlType<Integer> for diesel::pg::Pg {
            fn metadata(_: &mut Self::MetadataLookup)
                -> diesel::pg::PgTypeMetadata {
                diesel::pg::PgTypeMetadata::new(23, 1007)
            }
        }
    };SqlType)]
101#[diesel(postgres_type(oid = 23, array_oid = 1007))]
102#[diesel(sqlite_type(name = "Integer"))]
103#[diesel(mysql_type(name = "Long"))]
104pub struct Integer;
105#[doc(hidden)]
106pub type Int4 = Integer;
107
108/// The big integer SQL type.
109///
110/// ### [`ToSql`](crate::serialize::ToSql) impls
111///
112/// - [`i64`][i64]
113///
114/// ### [`FromSql`](crate::deserialize::FromSql) impls
115///
116/// - [`i64`][i64]
117///
118/// [i64]: https://doc.rust-lang.org/nightly/std/primitive.i64.html
119#[derive(#[automatically_derived]
impl ::core::fmt::Debug for BigInt {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::write_str(f, "BigInt")
    }
}Debug, #[automatically_derived]
impl ::core::clone::Clone for BigInt {
    #[inline]
    fn clone(&self) -> BigInt { *self }
}Clone, #[automatically_derived]
impl ::core::marker::Copy for BigInt { }Copy, #[automatically_derived]
impl ::core::default::Default for BigInt {
    #[inline]
    fn default() -> BigInt { BigInt {} }
}Default, const _: () =
    {
        use diesel;
        #[allow(non_camel_case_types)]
        impl diesel::query_builder::QueryId for BigInt {
            type QueryId = BigInt<>;
            const HAS_STATIC_QUERY_ID: bool = true;
            const IS_WINDOW_FUNCTION: bool = false;
        }
    };QueryId, const _: () =
    {
        use diesel;
        impl diesel::sql_types::SqlType for BigInt {
            type IsNull = diesel::sql_types::is_nullable::NotNull;
            const IS_ARRAY: bool = false;
        }
        impl diesel::sql_types::SingleValue for BigInt {}
        impl diesel::sql_types::HasSqlType<BigInt> for diesel::sqlite::Sqlite
            {
            fn metadata(_: &mut ()) -> diesel::sqlite::SqliteType {
                diesel::sqlite::SqliteType::Long
            }
        }
        impl diesel::sql_types::HasSqlType<BigInt> for diesel::mysql::Mysql {
            fn metadata(_: &mut ()) -> diesel::mysql::MysqlType {
                diesel::mysql::MysqlType::LongLong
            }
        }
        impl diesel::sql_types::HasSqlType<BigInt> for diesel::pg::Pg {
            fn metadata(_: &mut Self::MetadataLookup)
                -> diesel::pg::PgTypeMetadata {
                diesel::pg::PgTypeMetadata::new(20, 1016)
            }
        }
    };SqlType)]
120#[diesel(postgres_type(oid = 20, array_oid = 1016))]
121#[diesel(sqlite_type(name = "Long"))]
122#[diesel(mysql_type(name = "LongLong"))]
123pub struct BigInt;
124#[doc(hidden)]
125pub type Int8 = BigInt;
126#[doc(hidden)]
127pub type Bigint = BigInt;
128
129/// The float SQL type.
130///
131/// ### [`ToSql`](crate::serialize::ToSql) impls
132///
133/// - [`f32`][f32]
134///
135/// ### [`FromSql`](crate::deserialize::FromSql) impls
136///
137/// - [`f32`][f32]
138///
139/// [f32]: https://doc.rust-lang.org/nightly/std/primitive.f32.html
140#[derive(#[automatically_derived]
impl ::core::fmt::Debug for Float {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::write_str(f, "Float")
    }
}Debug, #[automatically_derived]
impl ::core::clone::Clone for Float {
    #[inline]
    fn clone(&self) -> Float { *self }
}Clone, #[automatically_derived]
impl ::core::marker::Copy for Float { }Copy, #[automatically_derived]
impl ::core::default::Default for Float {
    #[inline]
    fn default() -> Float { Float {} }
}Default, const _: () =
    {
        use diesel;
        #[allow(non_camel_case_types)]
        impl diesel::query_builder::QueryId for Float {
            type QueryId = Float<>;
            const HAS_STATIC_QUERY_ID: bool = true;
            const IS_WINDOW_FUNCTION: bool = false;
        }
    };QueryId, const _: () =
    {
        use diesel;
        impl diesel::sql_types::SqlType for Float {
            type IsNull = diesel::sql_types::is_nullable::NotNull;
            const IS_ARRAY: bool = false;
        }
        impl diesel::sql_types::SingleValue for Float {}
        impl diesel::sql_types::HasSqlType<Float> for diesel::sqlite::Sqlite {
            fn metadata(_: &mut ()) -> diesel::sqlite::SqliteType {
                diesel::sqlite::SqliteType::Float
            }
        }
        impl diesel::sql_types::HasSqlType<Float> for diesel::mysql::Mysql {
            fn metadata(_: &mut ()) -> diesel::mysql::MysqlType {
                diesel::mysql::MysqlType::Float
            }
        }
        impl diesel::sql_types::HasSqlType<Float> for diesel::pg::Pg {
            fn metadata(_: &mut Self::MetadataLookup)
                -> diesel::pg::PgTypeMetadata {
                diesel::pg::PgTypeMetadata::new(700, 1021)
            }
        }
    };SqlType)]
141#[diesel(postgres_type(oid = 700, array_oid = 1021))]
142#[diesel(sqlite_type(name = "Float"))]
143#[diesel(mysql_type(name = "Float"))]
144pub struct Float;
145#[doc(hidden)]
146pub type Float4 = Float;
147
148/// The double precision float SQL type.
149///
150/// ### [`ToSql`](crate::serialize::ToSql) impls
151///
152/// - [`f64`][f64]
153///
154/// ### [`FromSql`](crate::deserialize::FromSql) impls
155///
156/// - [`f64`][f64]
157///
158/// [f64]: https://doc.rust-lang.org/nightly/std/primitive.f64.html
159#[derive(#[automatically_derived]
impl ::core::fmt::Debug for Double {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::write_str(f, "Double")
    }
}Debug, #[automatically_derived]
impl ::core::clone::Clone for Double {
    #[inline]
    fn clone(&self) -> Double { *self }
}Clone, #[automatically_derived]
impl ::core::marker::Copy for Double { }Copy, #[automatically_derived]
impl ::core::default::Default for Double {
    #[inline]
    fn default() -> Double { Double {} }
}Default, const _: () =
    {
        use diesel;
        #[allow(non_camel_case_types)]
        impl diesel::query_builder::QueryId for Double {
            type QueryId = Double<>;
            const HAS_STATIC_QUERY_ID: bool = true;
            const IS_WINDOW_FUNCTION: bool = false;
        }
    };QueryId, const _: () =
    {
        use diesel;
        impl diesel::sql_types::SqlType for Double {
            type IsNull = diesel::sql_types::is_nullable::NotNull;
            const IS_ARRAY: bool = false;
        }
        impl diesel::sql_types::SingleValue for Double {}
        impl diesel::sql_types::HasSqlType<Double> for diesel::sqlite::Sqlite
            {
            fn metadata(_: &mut ()) -> diesel::sqlite::SqliteType {
                diesel::sqlite::SqliteType::Double
            }
        }
        impl diesel::sql_types::HasSqlType<Double> for diesel::mysql::Mysql {
            fn metadata(_: &mut ()) -> diesel::mysql::MysqlType {
                diesel::mysql::MysqlType::Double
            }
        }
        impl diesel::sql_types::HasSqlType<Double> for diesel::pg::Pg {
            fn metadata(_: &mut Self::MetadataLookup)
                -> diesel::pg::PgTypeMetadata {
                diesel::pg::PgTypeMetadata::new(701, 1022)
            }
        }
    };SqlType)]
160#[diesel(postgres_type(oid = 701, array_oid = 1022))]
161#[diesel(sqlite_type(name = "Double"))]
162#[diesel(mysql_type(name = "Double"))]
163pub struct Double;
164#[doc(hidden)]
165pub type Float8 = Double;
166
167/// The arbitrary precision numeric SQL type.
168///
169/// This type is only supported on PostgreSQL and MySQL.
170/// On SQLite, [`Double`] should be used instead.
171///
172/// ### [`ToSql`](crate::serialize::ToSql) impls
173///
174/// - [`bigdecimal::BigDecimal`] with `feature = ["numeric"]`
175///
176/// ### [`FromSql`](crate::deserialize::FromSql) impls
177///
178/// - [`bigdecimal::BigDecimal`] with `feature = ["numeric"]`
179///
180/// [`bigdecimal::BigDecimal`]: /bigdecimal/struct.BigDecimal.html
181#[derive(#[automatically_derived]
impl ::core::fmt::Debug for Numeric {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::write_str(f, "Numeric")
    }
}Debug, #[automatically_derived]
impl ::core::clone::Clone for Numeric {
    #[inline]
    fn clone(&self) -> Numeric { *self }
}Clone, #[automatically_derived]
impl ::core::marker::Copy for Numeric { }Copy, #[automatically_derived]
impl ::core::default::Default for Numeric {
    #[inline]
    fn default() -> Numeric { Numeric {} }
}Default, const _: () =
    {
        use diesel;
        #[allow(non_camel_case_types)]
        impl diesel::query_builder::QueryId for Numeric {
            type QueryId = Numeric<>;
            const HAS_STATIC_QUERY_ID: bool = true;
            const IS_WINDOW_FUNCTION: bool = false;
        }
    };QueryId, const _: () =
    {
        use diesel;
        impl diesel::sql_types::SqlType for Numeric {
            type IsNull = diesel::sql_types::is_nullable::NotNull;
            const IS_ARRAY: bool = false;
        }
        impl diesel::sql_types::SingleValue for Numeric {}
        impl diesel::sql_types::HasSqlType<Numeric> for diesel::sqlite::Sqlite
            {
            fn metadata(_: &mut ()) -> diesel::sqlite::SqliteType {
                diesel::sqlite::SqliteType::Double
            }
        }
        impl diesel::sql_types::HasSqlType<Numeric> for diesel::mysql::Mysql {
            fn metadata(_: &mut ()) -> diesel::mysql::MysqlType {
                diesel::mysql::MysqlType::Numeric
            }
        }
        impl diesel::sql_types::HasSqlType<Numeric> for diesel::pg::Pg {
            fn metadata(_: &mut Self::MetadataLookup)
                -> diesel::pg::PgTypeMetadata {
                diesel::pg::PgTypeMetadata::new(1700, 1231)
            }
        }
    };SqlType)]
182#[diesel(postgres_type(oid = 1700, array_oid = 1231))]
183#[diesel(mysql_type(name = "Numeric"))]
184#[diesel(sqlite_type(name = "Double"))]
185pub struct Numeric;
186
187/// Alias for `Numeric`
188pub type Decimal = Numeric;
189
190/// The text SQL type.
191///
192/// On all backends strings must be valid UTF-8.
193/// On PostgreSQL strings must not include nul bytes.
194///
195/// Schema inference will treat all variants of `TEXT` as this type (e.g.
196/// `VARCHAR`, `MEDIUMTEXT`, etc).
197///
198/// ### [`ToSql`](crate::serialize::ToSql) impls
199///
200/// - [`String`]
201/// - [`&str`][str]
202///
203/// ### [`FromSql`](crate::deserialize::FromSql) impls
204///
205/// - [`String`]
206///
207/// [str]: https://doc.rust-lang.org/nightly/std/primitive.str.html
208#[derive(#[automatically_derived]
impl ::core::fmt::Debug for Text {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::write_str(f, "Text")
    }
}Debug, #[automatically_derived]
impl ::core::clone::Clone for Text {
    #[inline]
    fn clone(&self) -> Text { *self }
}Clone, #[automatically_derived]
impl ::core::marker::Copy for Text { }Copy, #[automatically_derived]
impl ::core::default::Default for Text {
    #[inline]
    fn default() -> Text { Text {} }
}Default, const _: () =
    {
        use diesel;
        #[allow(non_camel_case_types)]
        impl diesel::query_builder::QueryId for Text {
            type QueryId = Text<>;
            const HAS_STATIC_QUERY_ID: bool = true;
            const IS_WINDOW_FUNCTION: bool = false;
        }
    };QueryId, const _: () =
    {
        use diesel;
        impl diesel::sql_types::SqlType for Text {
            type IsNull = diesel::sql_types::is_nullable::NotNull;
            const IS_ARRAY: bool = false;
        }
        impl diesel::sql_types::SingleValue for Text {}
        impl diesel::sql_types::HasSqlType<Text> for diesel::sqlite::Sqlite {
            fn metadata(_: &mut ()) -> diesel::sqlite::SqliteType {
                diesel::sqlite::SqliteType::Text
            }
        }
        impl diesel::sql_types::HasSqlType<Text> for diesel::mysql::Mysql {
            fn metadata(_: &mut ()) -> diesel::mysql::MysqlType {
                diesel::mysql::MysqlType::String
            }
        }
        impl diesel::sql_types::HasSqlType<Text> for diesel::pg::Pg {
            fn metadata(_: &mut Self::MetadataLookup)
                -> diesel::pg::PgTypeMetadata {
                diesel::pg::PgTypeMetadata::new(25, 1009)
            }
        }
    };SqlType)]
209#[diesel(postgres_type(oid = 25, array_oid = 1009))]
210#[diesel(sqlite_type(name = "Text"))]
211#[diesel(mysql_type(name = "String"))]
212pub struct Text;
213
214/// The SQL `VARCHAR` type
215///
216/// This type is generally interchangeable with `TEXT`, so Diesel has this as an
217/// alias rather than a separate type (Diesel does not currently support
218/// implicit coercions).
219///
220/// One notable exception to this is with arrays on PG. `TEXT[]` cannot be
221/// coerced to `VARCHAR[]`.  It is recommended that you always use `TEXT[]` if
222/// you need a string array on PG.
223pub type VarChar = Text;
224#[doc(hidden)]
225pub type Varchar = VarChar;
226#[doc(hidden)]
227pub type Char = Text;
228#[doc(hidden)]
229pub type Tinytext = Text;
230#[doc(hidden)]
231pub type Mediumtext = Text;
232#[doc(hidden)]
233pub type Longtext = Text;
234
235/// The binary SQL type.
236///
237/// Schema inference will treat all variants of `BLOB` as this type (e.g.
238/// `VARBINARY`, `MEDIUMBLOB`, etc).
239///
240/// ### [`ToSql`](crate::serialize::ToSql) impls
241///
242/// - [`Vec<u8>`][Vec]
243/// - [`&[u8]`][slice]
244///
245/// ### [`FromSql`](crate::deserialize::FromSql) impls
246///
247/// - [`Vec<u8>`][Vec]
248///
249/// [Vec]: std::vec::Vec
250/// [slice]: https://doc.rust-lang.org/nightly/std/primitive.slice.html
251#[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::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, const _: () =
    {
        use diesel;
        impl diesel::sql_types::SqlType for Binary {
            type IsNull = diesel::sql_types::is_nullable::NotNull;
            const IS_ARRAY: bool = false;
        }
        impl diesel::sql_types::SingleValue for Binary {}
        impl diesel::sql_types::HasSqlType<Binary> for diesel::sqlite::Sqlite
            {
            fn metadata(_: &mut ()) -> diesel::sqlite::SqliteType {
                diesel::sqlite::SqliteType::Binary
            }
        }
        impl diesel::sql_types::HasSqlType<Binary> for diesel::mysql::Mysql {
            fn metadata(_: &mut ()) -> diesel::mysql::MysqlType {
                diesel::mysql::MysqlType::Blob
            }
        }
        impl diesel::sql_types::HasSqlType<Binary> for diesel::pg::Pg {
            fn metadata(_: &mut Self::MetadataLookup)
                -> diesel::pg::PgTypeMetadata {
                diesel::pg::PgTypeMetadata::new(17, 1001)
            }
        }
    };SqlType)]
252#[diesel(postgres_type(oid = 17, array_oid = 1001))]
253#[diesel(sqlite_type(name = "Binary"))]
254#[diesel(mysql_type(name = "Blob"))]
255pub struct Binary;
256
257#[doc(hidden)]
258pub type Tinyblob = Binary;
259#[doc(hidden)]
260pub type Blob = Binary;
261#[doc(hidden)]
262pub type Mediumblob = Binary;
263#[doc(hidden)]
264pub type Longblob = Binary;
265#[doc(hidden)]
266pub type Varbinary = Binary;
267#[doc(hidden)]
268pub type Bit = Binary;
269
270/// The date SQL type.
271///
272/// ### [`ToSql`](crate::serialize::ToSql) impls
273///
274/// - [`chrono::NaiveDate`][NaiveDate] with `feature = "chrono"`
275/// - [`time::Date`][Date] with `feature = "time"`
276///
277/// ### [`FromSql`](crate::deserialize::FromSql) impls
278///
279/// - [`chrono::NaiveDate`][NaiveDate] with `feature = "chrono"`
280/// - [`time::Date`][Date] with `feature = "time"`
281///
282/// [NaiveDate]: https://docs.rs/chrono/*/chrono/naive/struct.NaiveDate.html
283/// [Date]: https://docs.rs/time/0.3.9/time/struct.Date.html
284#[derive(#[automatically_derived]
impl ::core::fmt::Debug for Date {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::write_str(f, "Date")
    }
}Debug, #[automatically_derived]
impl ::core::clone::Clone for Date {
    #[inline]
    fn clone(&self) -> Date { *self }
}Clone, #[automatically_derived]
impl ::core::marker::Copy for Date { }Copy, #[automatically_derived]
impl ::core::default::Default for Date {
    #[inline]
    fn default() -> Date { Date {} }
}Default, const _: () =
    {
        use diesel;
        #[allow(non_camel_case_types)]
        impl diesel::query_builder::QueryId for Date {
            type QueryId = Date<>;
            const HAS_STATIC_QUERY_ID: bool = true;
            const IS_WINDOW_FUNCTION: bool = false;
        }
    };QueryId, const _: () =
    {
        use diesel;
        impl diesel::sql_types::SqlType for Date {
            type IsNull = diesel::sql_types::is_nullable::NotNull;
            const IS_ARRAY: bool = false;
        }
        impl diesel::sql_types::SingleValue for Date {}
        impl diesel::sql_types::HasSqlType<Date> for diesel::sqlite::Sqlite {
            fn metadata(_: &mut ()) -> diesel::sqlite::SqliteType {
                diesel::sqlite::SqliteType::Text
            }
        }
        impl diesel::sql_types::HasSqlType<Date> for diesel::mysql::Mysql {
            fn metadata(_: &mut ()) -> diesel::mysql::MysqlType {
                diesel::mysql::MysqlType::Date
            }
        }
        impl diesel::sql_types::HasSqlType<Date> for diesel::pg::Pg {
            fn metadata(_: &mut Self::MetadataLookup)
                -> diesel::pg::PgTypeMetadata {
                diesel::pg::PgTypeMetadata::new(1082, 1182)
            }
        }
    };SqlType)]
285#[diesel(postgres_type(oid = 1082, array_oid = 1182))]
286#[diesel(sqlite_type(name = "Text"))]
287#[diesel(mysql_type(name = "Date"))]
288pub struct Date;
289
290/// The interval SQL type.
291///
292/// This type is currently only implemented for PostgreSQL.
293///
294/// ### [`ToSql`](crate::serialize::ToSql) impls
295///
296/// - [`PgInterval`] which can be constructed using [`IntervalDsl`]
297/// - [`chrono::Duration`][Duration] with `feature = "chrono"`
298///
299/// ### [`FromSql`](crate::deserialize::FromSql) impls
300///
301/// - [`PgInterval`] which can be constructed using [`IntervalDsl`]
302/// - [`chrono::Duration`][Duration] with `feature = "chrono"`
303///   (There might be some information loss due to special behavior for literal `month` (or longer) intervals;
304///   Please read official documentation of [PostgreSQL Interval].)
305///
306/// [`PgInterval`]: ../pg/data_types/struct.PgInterval.html
307/// [`IntervalDsl`]: ../pg/expression/extensions/trait.IntervalDsl.html
308/// [Duration]: https://docs.rs/chrono/*/chrono/type.Duration.html
309/// [PostgreSQL Interval]: https://www.postgresql.org/docs/current/datatype-datetime.html#DATATYPE-INTERVAL-INPUT
310#[derive(#[automatically_derived]
impl ::core::fmt::Debug for Interval {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::write_str(f, "Interval")
    }
}Debug, #[automatically_derived]
impl ::core::clone::Clone for Interval {
    #[inline]
    fn clone(&self) -> Interval { *self }
}Clone, #[automatically_derived]
impl ::core::marker::Copy for Interval { }Copy, #[automatically_derived]
impl ::core::default::Default for Interval {
    #[inline]
    fn default() -> Interval { Interval {} }
}Default, const _: () =
    {
        use diesel;
        #[allow(non_camel_case_types)]
        impl diesel::query_builder::QueryId for Interval {
            type QueryId = Interval<>;
            const HAS_STATIC_QUERY_ID: bool = true;
            const IS_WINDOW_FUNCTION: bool = false;
        }
    };QueryId, const _: () =
    {
        use diesel;
        impl diesel::sql_types::SqlType for Interval {
            type IsNull = diesel::sql_types::is_nullable::NotNull;
            const IS_ARRAY: bool = false;
        }
        impl diesel::sql_types::SingleValue for Interval {}
        impl diesel::sql_types::HasSqlType<Interval> for diesel::pg::Pg {
            fn metadata(_: &mut Self::MetadataLookup)
                -> diesel::pg::PgTypeMetadata {
                diesel::pg::PgTypeMetadata::new(1186, 1187)
            }
        }
    };SqlType)]
311#[diesel(postgres_type(oid = 1186, array_oid = 1187))]
312pub struct Interval;
313
314/// The time SQL type.
315///
316/// ### [`ToSql`](crate::serialize::ToSql) impls
317///
318/// - [`chrono::NaiveTime`][NaiveTime] with `feature = "chrono"`
319/// - [`time::Time`][Time] with `feature = "time"`
320///
321/// ### [`FromSql`](crate::deserialize::FromSql) impls
322///
323/// - [`chrono::NaiveTime`][NaiveTime] with `feature = "chrono"`
324/// - [`time::Time`][Time] with `feature = "time"`
325///
326/// [NaiveTime]: /chrono/naive/time/struct.NaiveTime.html
327/// [Time]: /time/struct.Time.html
328#[derive(#[automatically_derived]
impl ::core::fmt::Debug for Time {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::write_str(f, "Time")
    }
}Debug, #[automatically_derived]
impl ::core::clone::Clone for Time {
    #[inline]
    fn clone(&self) -> Time { *self }
}Clone, #[automatically_derived]
impl ::core::marker::Copy for Time { }Copy, #[automatically_derived]
impl ::core::default::Default for Time {
    #[inline]
    fn default() -> Time { Time {} }
}Default, const _: () =
    {
        use diesel;
        #[allow(non_camel_case_types)]
        impl diesel::query_builder::QueryId for Time {
            type QueryId = Time<>;
            const HAS_STATIC_QUERY_ID: bool = true;
            const IS_WINDOW_FUNCTION: bool = false;
        }
    };QueryId, const _: () =
    {
        use diesel;
        impl diesel::sql_types::SqlType for Time {
            type IsNull = diesel::sql_types::is_nullable::NotNull;
            const IS_ARRAY: bool = false;
        }
        impl diesel::sql_types::SingleValue for Time {}
        impl diesel::sql_types::HasSqlType<Time> for diesel::sqlite::Sqlite {
            fn metadata(_: &mut ()) -> diesel::sqlite::SqliteType {
                diesel::sqlite::SqliteType::Text
            }
        }
        impl diesel::sql_types::HasSqlType<Time> for diesel::mysql::Mysql {
            fn metadata(_: &mut ()) -> diesel::mysql::MysqlType {
                diesel::mysql::MysqlType::Time
            }
        }
        impl diesel::sql_types::HasSqlType<Time> for diesel::pg::Pg {
            fn metadata(_: &mut Self::MetadataLookup)
                -> diesel::pg::PgTypeMetadata {
                diesel::pg::PgTypeMetadata::new(1083, 1183)
            }
        }
    };SqlType)]
329#[diesel(postgres_type(oid = 1083, array_oid = 1183))]
330#[diesel(sqlite_type(name = "Text"))]
331#[diesel(mysql_type(name = "Time"))]
332pub struct Time;
333
334/// The timestamp SQL type.
335///
336/// ### [`ToSql`](crate::serialize::ToSql) impls
337///
338/// - [`std::time::SystemTime`][SystemTime] (PG only)
339/// - [`chrono::NaiveDateTime`][NaiveDateTime] with `feature = "chrono"`
340/// - [`time::PrimitiveDateTime`] with `feature = "time"`
341/// - [`time::OffsetDateTime`] with `feature = "time"` (MySQL only)
342///
343/// ### [`FromSql`](crate::deserialize::FromSql) impls
344///
345/// - [`std::time::SystemTime`][SystemTime] (PG only)
346/// - [`chrono::NaiveDateTime`][NaiveDateTime] with `feature = "chrono"`
347/// - [`time::PrimitiveDateTime`] with `feature = "time"`
348/// - [`time::OffsetDateTime`] with `feature = "time"` (MySQL only)
349///
350/// [SystemTime]: std::time::SystemTime
351#[cfg_attr(
352    feature = "chrono",
353    doc = " [NaiveDateTime]: chrono::naive::NaiveDateTime"
354)]
355#[cfg_attr(
356    not(feature = "chrono"),
357    doc = " [NaiveDateTime]: https://docs.rs/chrono/*/chrono/naive/struct.NaiveDateTime.html"
358)]
359#[cfg_attr(
360    feature = "time",
361    doc = " [`time::PrimitiveDateTime`]: time::PrimitiveDateTime"
362)]
363#[cfg_attr(
364    not(feature = "time"),
365    doc = " [`time::PrimitiveDateTime`]: https://docs.rs/time/0.3.9/time/struct.PrimitiveDateTime.html"
366)]
367#[cfg_attr(
368    feature = "time",
369    doc = " [`time::OffsetDateTime`]: time::OffsetDateTime"
370)]
371#[cfg_attr(
372    not(feature = "time"),
373    doc = " [`time::OffsetDateTime`]: https://docs.rs/time/0.3.9/time/struct.OffsetDateTime.html"
374)]
375/// [Timespec]: /time/struct.Timespec.html
376#[derive(#[automatically_derived]
impl ::core::fmt::Debug for Timestamp {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::write_str(f, "Timestamp")
    }
}Debug, #[automatically_derived]
impl ::core::clone::Clone for Timestamp {
    #[inline]
    fn clone(&self) -> Timestamp { *self }
}Clone, #[automatically_derived]
impl ::core::marker::Copy for Timestamp { }Copy, #[automatically_derived]
impl ::core::default::Default for Timestamp {
    #[inline]
    fn default() -> Timestamp { Timestamp {} }
}Default, const _: () =
    {
        use diesel;
        #[allow(non_camel_case_types)]
        impl diesel::query_builder::QueryId for Timestamp {
            type QueryId = Timestamp<>;
            const HAS_STATIC_QUERY_ID: bool = true;
            const IS_WINDOW_FUNCTION: bool = false;
        }
    };QueryId, const _: () =
    {
        use diesel;
        impl diesel::sql_types::SqlType for Timestamp {
            type IsNull = diesel::sql_types::is_nullable::NotNull;
            const IS_ARRAY: bool = false;
        }
        impl diesel::sql_types::SingleValue for Timestamp {}
        impl diesel::sql_types::HasSqlType<Timestamp> for
            diesel::sqlite::Sqlite {
            fn metadata(_: &mut ()) -> diesel::sqlite::SqliteType {
                diesel::sqlite::SqliteType::Text
            }
        }
        impl diesel::sql_types::HasSqlType<Timestamp> for diesel::mysql::Mysql
            {
            fn metadata(_: &mut ()) -> diesel::mysql::MysqlType {
                diesel::mysql::MysqlType::Timestamp
            }
        }
        impl diesel::sql_types::HasSqlType<Timestamp> for diesel::pg::Pg {
            fn metadata(_: &mut Self::MetadataLookup)
                -> diesel::pg::PgTypeMetadata {
                diesel::pg::PgTypeMetadata::new(1114, 1115)
            }
        }
    };SqlType)]
377#[diesel(postgres_type(oid = 1114, array_oid = 1115))]
378#[diesel(sqlite_type(name = "Text"))]
379#[diesel(mysql_type(name = "Timestamp"))]
380pub struct Timestamp;
381
382/// The JSON SQL type.  This type can only be used with `feature =
383/// "serde_json"`
384///
385/// For postgresql you should normally prefer [`Jsonb`](struct.Jsonb.html) instead,
386/// for the reasons discussed there.
387///
388/// ### [`ToSql`] impls
389///
390/// - [`serde_json::Value`]
391///
392/// ### [`FromSql`] impls
393///
394/// - [`serde_json::Value`]
395///
396/// [`ToSql`]: /serialize/trait.ToSql.html
397/// [`FromSql`]: /deserialize/trait.FromSql.html
398/// [`serde_json::Value`]: /../serde_json/value/enum.Value.html
399#[derive(#[automatically_derived]
impl ::core::fmt::Debug for Json {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::write_str(f, "Json")
    }
}Debug, #[automatically_derived]
impl ::core::clone::Clone for Json {
    #[inline]
    fn clone(&self) -> Json { *self }
}Clone, #[automatically_derived]
impl ::core::marker::Copy for Json { }Copy, #[automatically_derived]
impl ::core::default::Default for Json {
    #[inline]
    fn default() -> Json { Json {} }
}Default, const _: () =
    {
        use diesel;
        #[allow(non_camel_case_types)]
        impl diesel::query_builder::QueryId for Json {
            type QueryId = Json<>;
            const HAS_STATIC_QUERY_ID: bool = true;
            const IS_WINDOW_FUNCTION: bool = false;
        }
    };QueryId, const _: () =
    {
        use diesel;
        impl diesel::sql_types::SqlType for Json {
            type IsNull = diesel::sql_types::is_nullable::NotNull;
            const IS_ARRAY: bool = false;
        }
        impl diesel::sql_types::SingleValue for Json {}
        impl diesel::sql_types::HasSqlType<Json> for diesel::sqlite::Sqlite {
            fn metadata(_: &mut ()) -> diesel::sqlite::SqliteType {
                diesel::sqlite::SqliteType::Text
            }
        }
        impl diesel::sql_types::HasSqlType<Json> for diesel::mysql::Mysql {
            fn metadata(_: &mut ()) -> diesel::mysql::MysqlType {
                diesel::mysql::MysqlType::String
            }
        }
        impl diesel::sql_types::HasSqlType<Json> for diesel::pg::Pg {
            fn metadata(_: &mut Self::MetadataLookup)
                -> diesel::pg::PgTypeMetadata {
                diesel::pg::PgTypeMetadata::new(114, 199)
            }
        }
    };SqlType)]
400#[diesel(postgres_type(oid = 114, array_oid = 199))]
401#[diesel(mysql_type(name = "String"))]
402#[diesel(sqlite_type(name = "Text"))]
403pub struct Json;
404
405/// The [`jsonb`] SQL type.  This type can only be used with `feature =
406/// "serde_json"`
407///
408/// In SQLite, `jsonb` brings mainly [performance improvements][sqlite-adv] over
409/// regular JSON:
410///
411/// > The advantage of JSONB in SQLite is that it is smaller and faster than
412/// > text JSON - potentially several times faster. There is space in the
413/// > on-disk JSONB format to add enhancements and future versions of SQLite
414/// > might include options to provide O(1) lookup of elements in JSONB, but no
415/// > such capability is currently available.
416///
417/// <div class="warning">
418/// In SQLite, JSONB is intended for internal use by SQLite only. Thus, future
419/// SQLite updates might break our JSONB implementation. And one might have to
420/// wait and then upgrade <code>diesel</code> for those changes to be  accounted
421/// for. If you do not want this, prefer the regular
422/// <a href="./struct.Json.html"><code>Json</code></a> type.
423/// </div>
424///
425/// In PostgreSQL, `jsonb` offers [several advantages][pg-adv] over regular JSON:
426///
427/// > There are two JSON data types: `json` and `jsonb`. They accept almost
428/// > identical sets of values as input. The major practical difference
429/// > is one of efficiency. The `json` data type stores an exact copy of
430/// > the input text, which processing functions must reparse on each
431/// > execution; while `jsonb` data is stored in a decomposed binary format
432/// > that makes it slightly slower to input due to added conversion
433/// > overhead, but significantly faster to process, since no reparsing
434/// > is needed. `jsonb` also supports indexing, which can be a significant
435/// > advantage.
436/// >
437/// > ...In general, most applications should prefer to store JSON data as
438/// > `jsonb`, unless there are quite specialized needs, such as legacy
439/// > assumptions about ordering of object keys.
440///
441/// [pg-adv]: https://www.postgresql.org/docs/current/static/datatype-json.html
442/// [sqlite-adv]: https://sqlite.org/draft/jsonb.html
443///
444/// ### [`ToSql`] impls
445///
446/// - [`serde_json::Value`]
447///
448/// ### [`FromSql`] impls
449///
450/// - [`serde_json::Value`]
451///
452/// [`ToSql`]: crate::serialize::ToSql
453/// [`FromSql`]: crate::deserialize::FromSql
454/// [`jsonb`]: https://www.postgresql.org/docs/current/datatype-json.html
455#[cfg_attr(
456    feature = "serde_json",
457    doc = "[`serde_json::Value`]: serde_json::value::Value"
458)]
459#[cfg_attr(
460    not(feature = "serde_json"),
461    doc = "[`serde_json::Value`]: https://docs.rs/serde_json/1.0.64/serde_json/value/enum.Value.html"
462)]
463///
464/// ## Examples
465///
466/// ```rust
467/// # #![allow(dead_code)]
468/// # include!("../doctest_setup.rs");
469/// #
470/// table! {
471///     contacts {
472///         id -> Integer,
473///         name -> Text,
474///         address -> Jsonb,
475///     }
476/// }
477///
478/// # #[cfg(all(
479/// #   feature = "serde_json",
480/// #   any(
481/// #       feature = "postgres_backend",
482/// #       feature = "returning_clauses_for_sqlite_3_35",
483/// #   )
484/// # ))]
485/// # fn main() -> Result<(), Box<dyn std::error::Error>> {
486/// #     use diesel::insert_into;
487/// #     use self::contacts::dsl::*;
488/// #     let connection = &mut connection_no_data();
489/// # #[cfg(feature = "postgres_backend")]
490/// #     diesel::sql_query("CREATE TABLE contacts (
491/// #         id SERIAL PRIMARY KEY,
492/// #         name VARCHAR NOT NULL,
493/// #         address JSONB NOT NULL
494/// #     )").execute(connection)?;
495/// # #[cfg(feature = "__sqlite-shared")]
496/// #     diesel::sql_query("CREATE TABLE contacts (
497/// #         id INT PRIMARY KEY,
498/// #         name TEXT NOT NULL,
499/// #         address BLOB NOT NULL
500/// #     )").execute(connection)?;
501/// let santas_address: serde_json::Value = serde_json::from_str(
502///     r#"{
503///     "street": "Article Circle Expressway 1",
504///     "city": "North Pole",
505///     "postcode": "99705",
506///     "state": "Alaska"
507/// }"#,
508/// )?;
509/// let inserted_address = insert_into(contacts)
510///     .values((name.eq("Claus"), address.eq(&santas_address)))
511///     .returning(address)
512///     .get_result::<serde_json::Value>(connection)?;
513/// assert_eq!(santas_address, inserted_address);
514/// #     Ok(())
515/// # }
516/// # #[cfg(not(all(
517/// #   feature = "serde_json",
518/// #   any(
519/// #       feature = "postgres_backend",
520/// #       feature = "returning_clauses_for_sqlite_3_35",
521/// #   )
522/// # )))]
523/// # fn main() {}
524/// ```
525#[derive(#[automatically_derived]
impl ::core::fmt::Debug for Jsonb {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::write_str(f, "Jsonb")
    }
}Debug, #[automatically_derived]
impl ::core::clone::Clone for Jsonb {
    #[inline]
    fn clone(&self) -> Jsonb { *self }
}Clone, #[automatically_derived]
impl ::core::marker::Copy for Jsonb { }Copy, #[automatically_derived]
impl ::core::default::Default for Jsonb {
    #[inline]
    fn default() -> Jsonb { Jsonb {} }
}Default, const _: () =
    {
        use diesel;
        #[allow(non_camel_case_types)]
        impl diesel::query_builder::QueryId for Jsonb {
            type QueryId = Jsonb<>;
            const HAS_STATIC_QUERY_ID: bool = true;
            const IS_WINDOW_FUNCTION: bool = false;
        }
    };QueryId, const _: () =
    {
        use diesel;
        impl diesel::sql_types::SqlType for Jsonb {
            type IsNull = diesel::sql_types::is_nullable::NotNull;
            const IS_ARRAY: bool = false;
        }
        impl diesel::sql_types::SingleValue for Jsonb {}
        impl diesel::sql_types::HasSqlType<Jsonb> for diesel::sqlite::Sqlite {
            fn metadata(_: &mut ()) -> diesel::sqlite::SqliteType {
                diesel::sqlite::SqliteType::Binary
            }
        }
        impl diesel::sql_types::HasSqlType<Jsonb> for diesel::pg::Pg {
            fn metadata(_: &mut Self::MetadataLookup)
                -> diesel::pg::PgTypeMetadata {
                diesel::pg::PgTypeMetadata::new(3802, 3807)
            }
        }
    };SqlType)]
526#[diesel(postgres_type(oid = 3802, array_oid = 3807))]
527#[diesel(sqlite_type(name = "Binary"))]
528pub struct Jsonb;
529
530/// The nullable SQL type.
531///
532/// This wraps another SQL type to indicate that it can be null.
533/// By default all values are assumed to be `NOT NULL`.
534///
535/// ### [`ToSql`](crate::serialize::ToSql) impls
536///
537/// - Any `T` which implements `ToSql<ST>`
538/// - `Option<T>` for any `T` which implements `ToSql<ST>`
539///
540/// ### [`FromSql`](crate::deserialize::FromSql) impls
541///
542/// - `Option<T>` for any `T` which implements `FromSql<ST>`
543#[derive(#[automatically_derived]
impl<ST: ::core::fmt::Debug> ::core::fmt::Debug for Nullable<ST> {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::debug_tuple_field1_finish(f, "Nullable",
            &&self.0)
    }
}Debug, #[automatically_derived]
impl<ST: ::core::clone::Clone> ::core::clone::Clone for Nullable<ST> {
    #[inline]
    fn clone(&self) -> Nullable<ST> {
        Nullable(::core::clone::Clone::clone(&self.0))
    }
}Clone, #[automatically_derived]
impl<ST: ::core::marker::Copy> ::core::marker::Copy for Nullable<ST> { }Copy, #[automatically_derived]
impl<ST: ::core::default::Default> ::core::default::Default for Nullable<ST> {
    #[inline]
    fn default() -> Nullable<ST> {
        Nullable(::core::default::Default::default())
    }
}Default)]
544pub struct Nullable<ST>(ST);
545
546impl<ST> SqlType for Nullable<ST>
547where
548    ST: SqlType,
549{
550    type IsNull = is_nullable::IsNullable;
551}
552
553#[doc(inline)]
554#[cfg(feature = "postgres_backend")]
555pub use crate::pg::sql_types::*;
556
557#[doc(inline)]
558#[cfg(feature = "mysql_backend")]
559pub use crate::mysql::sql_types::{Datetime, Unsigned};
560
561#[doc(inline)]
562#[cfg(feature = "__sqlite-shared")]
563pub use crate::sqlite::sql_types::Timestamptz as TimestamptzSqlite;
564
565/// Indicates that a SQL type exists for a backend.
566///
567/// This trait can be derived using the [`SqlType` derive](derive@SqlType)
568///
569/// # Example
570///
571/// ```rust
572/// #[derive(diesel::sql_types::SqlType)]
573/// #[diesel(postgres_type(oid = 23, array_oid = 1007))]
574/// #[diesel(sqlite_type(name = "Integer"))]
575/// #[diesel(mysql_type(name = "Long"))]
576/// pub struct Integer;
577/// ```
578pub trait HasSqlType<ST>: TypeMetadata {
579    /// Fetch the metadata for the given type
580    ///
581    /// This method may use `lookup` to do dynamic runtime lookup. Implementors
582    /// of this method should not do dynamic lookup unless absolutely necessary
583    fn metadata(lookup: &mut Self::MetadataLookup) -> Self::TypeMetadata;
584}
585
586/// Information about how a backend stores metadata about given SQL types
587pub trait TypeMetadata {
588    /// The actual type used to represent metadata.
589    ///
590    /// On PostgreSQL, this is the type's OID.
591    /// On MySQL and SQLite, this is an enum representing all storage classes
592    /// they support.
593    type TypeMetadata;
594    /// The type used for runtime lookup of metadata.
595    ///
596    /// For most backends, which don't support user defined types, this will
597    /// be `()`.
598    type MetadataLookup: ?Sized;
599}
600
601/// Converts a type which may or may not be nullable into its nullable
602/// representation.
603pub trait IntoNullable {
604    /// The nullable representation of this type.
605    ///
606    /// For all types except `Nullable`, this will be `Nullable<Self>`.
607    type Nullable;
608}
609
610impl<T> IntoNullable for T
611where
612    T: SqlType<IsNull = is_nullable::NotNull> + SingleValue,
613{
614    type Nullable = Nullable<T>;
615}
616
617impl<T> IntoNullable for Nullable<T>
618where
619    T: SqlType,
620{
621    type Nullable = Self;
622}
623
624/// Converts a type which may or may not be nullable into its not nullable
625/// representation.
626pub trait IntoNotNullable {
627    /// The not nullable representation of this type.
628    ///
629    /// For `Nullable<T>`, this will be `T` otherwise the type itself
630    type NotNullable;
631}
632
633impl<T> IntoNotNullable for T
634where
635    T: SqlType<IsNull = is_nullable::NotNull>,
636{
637    type NotNullable = T;
638}
639
640impl<T> IntoNotNullable for Nullable<T>
641where
642    T: SqlType,
643{
644    type NotNullable = T;
645}
646
647/// A marker trait indicating that a SQL type represents a single value, as
648/// opposed to a list of values.
649///
650/// This trait should generally be implemented for all SQL types with the
651/// exception of Rust tuples. If a column could have this as its type, this
652/// trait should be implemented.
653///
654/// # Deriving
655///
656/// This trait is automatically implemented by [`#[derive(SqlType)]`](derive@SqlType)
657pub trait SingleValue: SqlType {}
658
659impl<T: SqlType + SingleValue> SingleValue for Nullable<T> {}
660
661#[doc(inline)]
662pub use diesel_derives::DieselNumericOps;
663#[doc(inline)]
664pub use diesel_derives::SqlType;
665
666/// A marker trait for SQL types
667///
668/// # Deriving
669///
670/// This trait is automatically implemented by [`#[derive(SqlType)]`](derive@SqlType)
671/// which sets `IsNull` to [`is_nullable::NotNull`]
672pub trait SqlType: 'static {
673    /// Is this type nullable?
674    ///
675    /// This type should always be one of the structs in the ['is_nullable`]
676    /// module. See the documentation of those structs for more details.
677    ///
678    /// ['is_nullable`]: is_nullable
679    type IsNull: OneIsNullable<is_nullable::IsNullable> + OneIsNullable<is_nullable::NotNull>;
680
681    #[doc(hidden)]
682    const IS_ARRAY: bool = false;
683}
684
685/// A marker trait for SQL types representing database side enums
686///
687/// This trait describes how an enum should be mapped to the underlying database storage type
688/// by specifying one of a set of different strategies.
689///
690/// The generic constant `HAS_EXPLICIT_DISCRIMINANT` can be used to enforce that for a given mapping
691/// the user needs to provide explicit discriminant values. The [`#[derive(Enum)]`](crate::types::Enum) macro
692/// will pass the true only if this is the case.
693///
694/// The generic type `DB` represents the database backend for which this mapping is valid
695///
696/// # Deriving
697///
698/// This trait can be automatically derived by using [`#[derive(SqlType)]`](derive@SqlType)
699/// with the `#[diesel(enum_type)]` attribute
700#[doc = " A marker trait for SQL types representing database side enums"]
#[doc = ""]
#[doc =
" This trait describes how an enum should be mapped to the underlying database storage type"]
#[doc = " by specifying one of a set of different strategies."]
#[doc = ""]
#[doc =
" The generic constant `HAS_EXPLICIT_DISCRIMINANT` can be used to enforce that for a given mapping"]
#[doc =
" the user needs to provide explicit discriminant values. The [`#[derive(Enum)]`](crate::types::Enum) macro"]
#[doc = " will pass the true only if this is the case."]
#[doc = ""]
#[doc =
" The generic type `DB` represents the database backend for which this mapping is valid"]
#[doc = ""]
#[doc = " # Deriving"]
#[doc = ""]
#[doc =
" This trait can be automatically derived by using [`#[derive(SqlType)]`](derive@SqlType)"]
#[doc = " with the `#[diesel(enum_type)]` attribute"]
pub trait EnumSqlType<const HAS_EXPLICIT_DISCRIMINANT : bool,
    DB: Backend>: SqlType {
    /// The mapping strategy used by this type
    ///
    /// This mainly exists to share the logic between different SQL types
    type Strategy: crate::types::enum_::EnumMapping<DB>;
}#[diesel_derives::__diesel_public_if(
701    feature = "i-implement-a-third-party-backend-and-opt-into-breaking-changes"
702)]
703// TODO: it seems like `#[diagnostic::on_unimplemented]` doesn't work here
704pub trait EnumSqlType<const HAS_EXPLICIT_DISCRIMINANT: bool, DB: Backend>: SqlType {
705    /// The mapping strategy used by this type
706    ///
707    /// This mainly exists to share the logic between different SQL types
708    type Strategy: crate::types::enum_::EnumMapping<DB>;
709}
710
711/// Is one value of `IsNull` nullable?
712///
713/// You should never implement this trait.
714pub trait OneIsNullable<Other> {
715    /// See the trait documentation
716    type Out: OneIsNullable<is_nullable::IsNullable> + OneIsNullable<is_nullable::NotNull>;
717}
718
719/// Are both values of `IsNull` are nullable?
720pub trait AllAreNullable<Other> {
721    /// See the trait documentation
722    type Out: AllAreNullable<is_nullable::NotNull> + AllAreNullable<is_nullable::IsNullable>;
723}
724
725/// A type level constructor for maybe nullable types
726///
727/// Constructs either `Nullable<O>` (for `Self` == `is_nullable::IsNullable`)
728/// or `O` (for `Self` == `is_nullable::NotNull`)
729pub trait MaybeNullableType<O> {
730    /// See the trait documentation
731    type Out: SqlType + TypedExpressionType;
732}
733
734/// Possible values for `SqlType::IsNullable`
735pub mod is_nullable {
736    use super::*;
737
738    /// No, this type cannot be null as it is marked as `NOT NULL` at database level
739    ///
740    /// This should be chosen for basically all manual impls of `SqlType`
741    /// beside implementing your own `Nullable<>` wrapper type
742    #[derive(#[automatically_derived]
impl ::core::fmt::Debug for NotNull {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::write_str(f, "NotNull")
    }
}Debug, #[automatically_derived]
impl ::core::clone::Clone for NotNull {
    #[inline]
    fn clone(&self) -> NotNull { *self }
}Clone, #[automatically_derived]
impl ::core::marker::Copy for NotNull { }Copy)]
743    pub struct NotNull;
744
745    /// Yes, this type can be null
746    ///
747    /// The only diesel provided `SqlType` that uses this value is [`Nullable<T>`]
748    ///
749    /// [`Nullable<T>`]: Nullable
750    #[derive(#[automatically_derived]
impl ::core::fmt::Debug for IsNullable {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::write_str(f, "IsNullable")
    }
}Debug, #[automatically_derived]
impl ::core::clone::Clone for IsNullable {
    #[inline]
    fn clone(&self) -> IsNullable { *self }
}Clone, #[automatically_derived]
impl ::core::marker::Copy for IsNullable { }Copy)]
751    pub struct IsNullable;
752
753    impl OneIsNullable<NotNull> for NotNull {
754        type Out = NotNull;
755    }
756
757    impl OneIsNullable<IsNullable> for NotNull {
758        type Out = IsNullable;
759    }
760
761    impl OneIsNullable<NotNull> for IsNullable {
762        type Out = IsNullable;
763    }
764
765    impl OneIsNullable<IsNullable> for IsNullable {
766        type Out = IsNullable;
767    }
768
769    impl AllAreNullable<NotNull> for NotNull {
770        type Out = NotNull;
771    }
772
773    impl AllAreNullable<IsNullable> for NotNull {
774        type Out = NotNull;
775    }
776
777    impl AllAreNullable<NotNull> for IsNullable {
778        type Out = NotNull;
779    }
780
781    impl AllAreNullable<IsNullable> for IsNullable {
782        type Out = IsNullable;
783    }
784
785    impl<O> MaybeNullableType<O> for NotNull
786    where
787        O: SqlType + TypedExpressionType,
788    {
789        type Out = O;
790    }
791
792    impl<O> MaybeNullableType<O> for IsNullable
793    where
794        O: SqlType,
795        Nullable<O>: TypedExpressionType,
796    {
797        type Out = Nullable<O>;
798    }
799
800    /// Represents the output type of [`MaybeNullableType`]
801    pub type MaybeNullable<N, T> = <N as MaybeNullableType<T>>::Out;
802
803    /// Represents the output type of [`OneIsNullable`]
804    pub type OneNullable<T1, T2> = <T1 as OneIsNullable<T2>>::Out;
805
806    /// Represents the output type of [`OneIsNullable`]
807    /// for two given SQL types
808    pub type IsOneNullable<S1, S2> = OneNullable<IsSqlTypeNullable<S1>, IsSqlTypeNullable<S2>>;
809
810    /// Represents the output type of [`AllAreNullable`]
811    /// for two given SQL types
812    pub type AreAllNullable<S1, S2> =
813        <IsSqlTypeNullable<S1> as AllAreNullable<IsSqlTypeNullable<S2>>>::Out;
814
815    /// Represents if the SQL type is nullable or not
816    pub type IsSqlTypeNullable<T> = <T as SqlType>::IsNull;
817}
818
819/// A marker trait for accepting expressions of the type `Bool` and
820/// `Nullable<Bool>` in the same place
821#[diagnostic::on_unimplemented(
822    message = "`{Self}` is neither `diesel::sql_types::Bool` nor `diesel::sql_types::Nullable<Bool>`",
823    note = "try to provide an expression that produces one of the expected sql types"
824)]
825pub trait BoolOrNullableBool {}
826
827impl BoolOrNullableBool for Bool {}
828impl BoolOrNullableBool for Nullable<Bool> {}
829
830#[doc(inline)]
831pub use crate::expression::expression_types::Untyped;
832
833pub(crate) mod helper {
834    use super::{MaybeNullableType, OneIsNullable, SingleValue};
835
836    pub trait CombinedNullableValue<O, Out>: SingleValue {
837        type Out: SingleValue;
838    }
839
840    impl<T, O, Out> CombinedNullableValue<O, Out> for T
841    where
842        T: SingleValue,
843        O: SingleValue,
844        T::IsNull: OneIsNullable<O::IsNull>,
845        <T::IsNull as OneIsNullable<O::IsNull>>::Out: MaybeNullableType<Out>,
846        <<T::IsNull as OneIsNullable<O::IsNull>>::Out as MaybeNullableType<Out>>::Out: SingleValue,
847    {
848        type Out = <<T::IsNull as OneIsNullable<O::IsNull>>::Out as MaybeNullableType<Out>>::Out;
849    }
850}