diff --git a/diesel/src/pg/expression/expression_methods.rs b/diesel/src/pg/expression/expression_methods.rs index faa32d9f1a84..26abac053daf 100644 --- a/diesel/src/pg/expression/expression_methods.rs +++ b/diesel/src/pg/expression/expression_methods.rs @@ -1,10 +1,14 @@ //! PostgreSQL specific expression methods +#[cfg(all(feature = "postgres_backend", feature = "serde_json"))] +pub(in crate::pg) use self::private::json::{ + JsonIndex, JsonOrNullableJson, JsonOrNullableJsonOrJsonbOrNullableJsonb, JsonRemoveIndex, + JsonbOrNullableJsonb, TextArrayOrNullableTextArray, +}; pub(in crate::pg) use self::private::{ - ArrayOrNullableArray, CombinedNullableValue, InetOrCidr, JsonIndex, JsonOrNullableJson, - JsonOrNullableJsonOrJsonbOrNullableJsonb, JsonRemoveIndex, JsonbOrNullableJsonb, - MaybeNullableValue, MultirangeOrNullableMultirange, MultirangeOrRangeMaybeNullable, - RangeHelper, RangeOrNullableRange, TextArrayOrNullableTextArray, TextOrNullableText, + ArrayOrNullableArray, CombinedNullableValue, InetOrCidr, MaybeNullableValue, + MultirangeOrNullableMultirange, MultirangeOrRangeMaybeNullable, RangeHelper, + RangeOrNullableRange, TextOrNullableText, }; use super::date_and_time::{AtTimeZone, DateTimeLike}; use super::operators::*; @@ -13,7 +17,9 @@ use crate::expression::grouped::Grouped; use crate::expression::operators::{Asc, Concat, Desc, Like, NotLike}; use crate::expression::{AsExpression, Expression, IntoSql, TypedExpressionType}; use crate::pg::expression::expression_methods::private::BinaryOrNullableBinary; -use crate::sql_types::{Array, Inet, Integer, Range, SqlType, Text, VarChar}; +#[cfg(all(feature = "postgres_backend", feature = "serde_json"))] +use crate::sql_types::Array; +use crate::sql_types::{Inet, Integer, Range, SqlType, Text, VarChar}; use crate::EscapeExpressionMethods; /// PostgreSQL specific methods which are present on all expressions. @@ -2255,7 +2261,7 @@ where } /// PostgreSQL specific methods present on JSONB expressions. -#[cfg(feature = "postgres_backend")] +#[cfg(all(feature = "postgres_backend", feature = "serde_json"))] pub trait PgJsonbExpressionMethods: Expression + Sized { /// Creates a PostgreSQL `||` expression. /// @@ -2866,6 +2872,7 @@ pub trait PgJsonbExpressionMethods: Expression + Sized { } } +#[cfg(all(feature = "postgres_backend", feature = "serde_json"))] impl PgJsonbExpressionMethods for T where T: Expression, @@ -2874,7 +2881,7 @@ where } /// PostgreSQL specific methods present on JSON and JSONB expressions. -#[cfg(feature = "postgres_backend")] +#[cfg(all(feature = "postgres_backend", feature = "serde_json"))] pub trait PgAnyJsonExpressionMethods: Expression + Sized { /// Creates a PostgreSQL `->` expression. /// @@ -3239,6 +3246,7 @@ pub trait PgAnyJsonExpressionMethods: Expression + Sized { } #[doc(hidden)] +#[cfg(all(feature = "postgres_backend", feature = "serde_json"))] impl PgAnyJsonExpressionMethods for T where T: Expression, @@ -3418,12 +3426,9 @@ where pub(in crate::pg) mod private { use crate::sql_types::{ - Array, Binary, Cidr, Inet, Integer, MaybeNullableType, Multirange, Nullable, OneIsNullable, - Range, SingleValue, SqlType, Text, + Array, Binary, Cidr, Inet, MaybeNullableType, Multirange, Nullable, OneIsNullable, Range, + SingleValue, SqlType, Text, }; - #[cfg(feature = "serde_json")] - use crate::sql_types::{Json, Jsonb}; - use crate::{Expression, IntoSql}; /// Marker trait used to implement `ArrayExpressionMethods` on the appropriate /// types. Once coherence takes associated types into account, we can remove @@ -3544,170 +3549,184 @@ pub(in crate::pg) mod private { type Inner = ST; } - /// Marker trait used to implement `PgJsonbExpressionMethods` on the appropriate types. - #[diagnostic::on_unimplemented( - message = "`{Self}` is neither `diesel::sql_types::Jsonb` nor `diesel::sql_types::Nullable`", - note = "try to provide an expression that produces one of the expected sql types" - )] - pub trait JsonbOrNullableJsonb {} - - impl JsonbOrNullableJsonb for Jsonb {} - impl JsonbOrNullableJsonb for Nullable {} - - #[diagnostic::on_unimplemented( - message = "`{Self}` is neither `diesel::sql_types::Json` nor `diesel::sql_types::Nullable`", - note = "try to provide an expression that produces one of the expected sql types" - )] - pub trait JsonOrNullableJson {} - - #[cfg(feature = "serde_json")] - impl JsonOrNullableJson for Json {} #[cfg(feature = "serde_json")] - impl JsonOrNullableJson for Nullable {} - - /// A trait that describes valid json indices used by postgresql - pub trait JsonRemoveIndex { - /// The Expression node created by this index type - type Expression: Expression; - - /// Convert a index value into the corresponding index expression - fn into_json_index_expression(self) -> Self::Expression; - } + pub(super) mod json { + use super::*; + use crate::sql_types::{Integer, Json, Jsonb}; + use crate::{Expression, IntoSql}; + + /// Marker trait used to implement `PgJsonbExpressionMethods` on the appropriate types. + #[diagnostic::on_unimplemented( + message = "`{Self}` is neither `diesel::sql_types::Jsonb` nor `diesel::sql_types::Nullable`", + note = "try to provide an expression that produces one of the expected sql types" + )] + pub trait JsonbOrNullableJsonb {} + + impl JsonbOrNullableJsonb for Jsonb {} + impl JsonbOrNullableJsonb for Nullable {} + + #[diagnostic::on_unimplemented( + message = "`{Self}` is neither `diesel::sql_types::Json` nor `diesel::sql_types::Nullable`", + note = "try to provide an expression that produces one of the expected sql types" + )] + pub trait JsonOrNullableJson {} + + impl JsonOrNullableJson for Json {} + impl JsonOrNullableJson for Nullable {} + + /// A trait that describes valid json indices used by postgresql + pub trait JsonRemoveIndex { + /// The Expression node created by this index type + type Expression: Expression; + + /// Convert a index value into the corresponding index expression + fn into_json_index_expression(self) -> Self::Expression; + } - impl<'a> JsonRemoveIndex for &'a str { - type Expression = crate::dsl::AsExprOf<&'a str, crate::sql_types::Text>; + impl<'a> JsonRemoveIndex for &'a str { + type Expression = crate::dsl::AsExprOf<&'a str, crate::sql_types::Text>; - fn into_json_index_expression(self) -> Self::Expression { - self.into_sql::() + fn into_json_index_expression(self) -> Self::Expression { + self.into_sql::() + } } - } - impl JsonRemoveIndex for String { - type Expression = crate::dsl::AsExprOf; + impl JsonRemoveIndex for String { + type Expression = crate::dsl::AsExprOf; - fn into_json_index_expression(self) -> Self::Expression { - self.into_sql::() + fn into_json_index_expression(self) -> Self::Expression { + self.into_sql::() + } } - } - impl JsonRemoveIndex for Vec { - type Expression = crate::dsl::AsExprOf>; + impl JsonRemoveIndex for Vec { + type Expression = crate::dsl::AsExprOf>; - fn into_json_index_expression(self) -> Self::Expression { - self.into_sql::>() + fn into_json_index_expression(self) -> Self::Expression { + self.into_sql::>() + } } - } - impl<'a> JsonRemoveIndex for Vec<&'a str> { - type Expression = crate::dsl::AsExprOf>; + impl<'a> JsonRemoveIndex for Vec<&'a str> { + type Expression = crate::dsl::AsExprOf>; - fn into_json_index_expression(self) -> Self::Expression { - self.into_sql::>() + fn into_json_index_expression(self) -> Self::Expression { + self.into_sql::>() + } } - } - impl<'a> JsonRemoveIndex for &'a [&'a str] { - type Expression = crate::dsl::AsExprOf>; + impl<'a> JsonRemoveIndex for &'a [&'a str] { + type Expression = crate::dsl::AsExprOf>; - fn into_json_index_expression(self) -> Self::Expression { - self.into_sql::>() + fn into_json_index_expression(self) -> Self::Expression { + self.into_sql::>() + } } - } - impl JsonRemoveIndex for i32 { - type Expression = crate::dsl::AsExprOf; + impl JsonRemoveIndex for i32 { + type Expression = crate::dsl::AsExprOf; - fn into_json_index_expression(self) -> Self::Expression { - self.into_sql::() + fn into_json_index_expression(self) -> Self::Expression { + self.into_sql::() + } } - } - impl JsonRemoveIndex for T - where - T: Expression, - T::SqlType: TextArrayOrTextOrInteger, - { - type Expression = Self; + impl JsonRemoveIndex for T + where + T: Expression, + T::SqlType: TextArrayOrTextOrInteger, + { + type Expression = Self; - fn into_json_index_expression(self) -> Self::Expression { - self + fn into_json_index_expression(self) -> Self::Expression { + self + } } - } - #[diagnostic::on_unimplemented( - message = "`{Self}` is neither `diesel::sql_types::Text`, `diesel::sql_types::Integer` nor `diesel::sql_types::Array`", - note = "try to provide an expression that produces one of the expected sql types" - )] - pub trait TextArrayOrTextOrInteger {} + #[diagnostic::on_unimplemented( + message = "`{Self}` is neither `diesel::sql_types::Text`, `diesel::sql_types::Integer` nor `diesel::sql_types::Array`", + note = "try to provide an expression that produces one of the expected sql types" + )] + pub trait TextArrayOrTextOrInteger {} - impl TextArrayOrTextOrInteger for Array {} - impl TextArrayOrTextOrInteger for Text {} - impl TextArrayOrTextOrInteger for Integer {} + impl TextArrayOrTextOrInteger for Array {} + impl TextArrayOrTextOrInteger for Text {} + impl TextArrayOrTextOrInteger for Integer {} - /// Marker trait used to implement `PgAnyJsonExpressionMethods` on the appropriate types. - #[diagnostic::on_unimplemented( - message = "`{Self}` is neither `diesel::sql_types::Json`, `diesel::sql_types::Jsonb`, `diesel::sql_types::Nullable` nor `diesel::sql_types::Nullable`", - note = "try to provide an expression that produces one of the expected sql types" - )] - pub trait JsonOrNullableJsonOrJsonbOrNullableJsonb {} - #[cfg(feature = "serde_json")] - impl JsonOrNullableJsonOrJsonbOrNullableJsonb for Json {} - #[cfg(feature = "serde_json")] - impl JsonOrNullableJsonOrJsonbOrNullableJsonb for Nullable {} - #[cfg(feature = "serde_json")] - impl JsonOrNullableJsonOrJsonbOrNullableJsonb for Jsonb {} - #[cfg(feature = "serde_json")] - impl JsonOrNullableJsonOrJsonbOrNullableJsonb for Nullable {} + /// Marker trait used to implement `PgAnyJsonExpressionMethods` on the appropriate types. + #[diagnostic::on_unimplemented( + message = "`{Self}` is neither `diesel::sql_types::Json`, `diesel::sql_types::Jsonb`, `diesel::sql_types::Nullable` nor `diesel::sql_types::Nullable`", + note = "try to provide an expression that produces one of the expected sql types" + )] + pub trait JsonOrNullableJsonOrJsonbOrNullableJsonb {} - pub trait JsonIndex { - type Expression: Expression; + impl JsonOrNullableJsonOrJsonbOrNullableJsonb for Json {} + impl JsonOrNullableJsonOrJsonbOrNullableJsonb for Nullable {} + impl JsonOrNullableJsonOrJsonbOrNullableJsonb for Jsonb {} + impl JsonOrNullableJsonOrJsonbOrNullableJsonb for Nullable {} - fn into_json_index_expression(self) -> Self::Expression; - } + pub trait JsonIndex { + type Expression: Expression; + + fn into_json_index_expression(self) -> Self::Expression; + } - impl<'a> JsonIndex for &'a str { - type Expression = crate::dsl::AsExprOf<&'a str, crate::sql_types::Text>; + impl<'a> JsonIndex for &'a str { + type Expression = crate::dsl::AsExprOf<&'a str, crate::sql_types::Text>; - fn into_json_index_expression(self) -> Self::Expression { - self.into_sql::() + fn into_json_index_expression(self) -> Self::Expression { + self.into_sql::() + } } - } - impl JsonIndex for String { - type Expression = crate::dsl::AsExprOf; + impl JsonIndex for String { + type Expression = crate::dsl::AsExprOf; - fn into_json_index_expression(self) -> Self::Expression { - self.into_sql::() + fn into_json_index_expression(self) -> Self::Expression { + self.into_sql::() + } } - } - impl JsonIndex for i32 { - type Expression = crate::dsl::AsExprOf; + impl JsonIndex for i32 { + type Expression = crate::dsl::AsExprOf; - fn into_json_index_expression(self) -> Self::Expression { - self.into_sql::() + fn into_json_index_expression(self) -> Self::Expression { + self.into_sql::() + } } - } - impl JsonIndex for T - where - T: Expression, - T::SqlType: TextOrInteger, - { - type Expression = Self; + impl JsonIndex for T + where + T: Expression, + T::SqlType: TextOrInteger, + { + type Expression = Self; - fn into_json_index_expression(self) -> Self::Expression { - self + fn into_json_index_expression(self) -> Self::Expression { + self + } } - } - #[diagnostic::on_unimplemented( - message = "`{Self}` is neither `diesel::sql_types::Text` nor `diesel::sql_types::Integer`", - note = "try to provide an expression that produces one of the expected sql types" - )] - pub trait TextOrInteger {} - impl TextOrInteger for Text {} - impl TextOrInteger for Integer {} + #[diagnostic::on_unimplemented( + message = "`{Self}` is neither `diesel::sql_types::Text` nor `diesel::sql_types::Integer`", + note = "try to provide an expression that produces one of the expected sql types" + )] + pub trait TextOrInteger {} + impl TextOrInteger for Text {} + impl TextOrInteger for Integer {} + + #[diagnostic::on_unimplemented( + message = "`{Self}` is neither `Array`, `Array>`,\ + `Nullable>` nor `diesel::sql_types::Nullable>>`", + note = "try to provide an expression that produces one of the expected sql types" + )] + pub trait TextArrayOrNullableTextArray {} + + impl TextArrayOrNullableTextArray for Array {} + impl TextArrayOrNullableTextArray for Array> {} + impl TextArrayOrNullableTextArray for Nullable> {} + impl TextArrayOrNullableTextArray for Nullable>> {} + } #[diagnostic::on_unimplemented( message = "`{Self}` is neither `diesel::sql_types::Binary` nor `diesel::sql_types::Nullable`", @@ -3745,16 +3764,4 @@ pub(in crate::pg) mod private { { type Out = <>::Out as MaybeNullableType>::Out; } - - #[diagnostic::on_unimplemented( - message = "`{Self}` is neither `Array`, `Array>`,\ - `Nullable>` nor `diesel::sql_types::Nullable>>`", - note = "try to provide an expression that produces one of the expected sql types" - )] - pub trait TextArrayOrNullableTextArray {} - - impl TextArrayOrNullableTextArray for Array {} - impl TextArrayOrNullableTextArray for Array> {} - impl TextArrayOrNullableTextArray for Nullable> {} - impl TextArrayOrNullableTextArray for Nullable>> {} } diff --git a/diesel/src/pg/expression/functions.rs b/diesel/src/pg/expression/functions.rs index 2feb1ce4d0f0..eb7056a52c39 100644 --- a/diesel/src/pg/expression/functions.rs +++ b/diesel/src/pg/expression/functions.rs @@ -4,13 +4,14 @@ use super::expression_methods::InetOrCidr; use crate::expression::functions::define_sql_function; use crate::pg::expression::expression_methods::ArrayOrNullableArray; use crate::pg::expression::expression_methods::CombinedNullableValue; -use crate::pg::expression::expression_methods::JsonOrNullableJson; -use crate::pg::expression::expression_methods::JsonbOrNullableJsonb; use crate::pg::expression::expression_methods::MaybeNullableValue; use crate::pg::expression::expression_methods::MultirangeOrNullableMultirange; use crate::pg::expression::expression_methods::MultirangeOrRangeMaybeNullable; use crate::pg::expression::expression_methods::RangeOrNullableRange; -use crate::pg::expression::expression_methods::TextArrayOrNullableTextArray; +#[cfg(all(feature = "postgres_backend", feature = "serde_json"))] +use crate::pg::expression::expression_methods::{ + JsonOrNullableJson, JsonbOrNullableJsonb, TextArrayOrNullableTextArray, +}; use crate::sql_types::*; define_sql_function! { @@ -1564,7 +1565,7 @@ define_sql_function! { fn to_json>(e: E) -> E::Out; } -#[cfg(feature = "postgres_backend")] +#[cfg(all(feature = "postgres_backend", feature = "serde_json"))] define_sql_function! { /// Converts any SQL value to jsonb /// @@ -1610,7 +1611,7 @@ define_sql_function! { fn to_jsonb>(e: E) -> E::Out; } -#[cfg(feature = "postgres_backend")] +#[cfg(all(feature = "postgres_backend", feature = "serde_json"))] define_sql_function! { /// Builds a JSON object out of a text array. The array must have an even number of members, /// in which case they are taken as alternating key/value pairs @@ -1658,7 +1659,7 @@ define_sql_function! { ) -> Arr::Out; } -#[cfg(feature = "postgres_backend")] +#[cfg(all(feature = "postgres_backend", feature = "serde_json"))] define_sql_function! { /// This form of json_object takes keys and values pairwise from two separate arrays. /// In all other respects it is identical to the one-argument form. @@ -1709,7 +1710,7 @@ define_sql_function! { ) -> Arr2::Out; } -#[cfg(feature = "postgres_backend")] +#[cfg(all(feature = "postgres_backend", feature = "serde_json"))] define_sql_function! { /// Returns the type of the top-level json value as a text-string /// @@ -1769,7 +1770,7 @@ define_sql_function! { fn json_typeof>(e: E) -> E::Out; } -#[cfg(feature = "postgres_backend")] +#[cfg(all(feature = "postgres_backend", feature = "serde_json"))] define_sql_function! { /// Returns the type of the top-level jsonb value as a text-string /// @@ -1829,7 +1830,7 @@ define_sql_function! { fn jsonb_typeof>(e: E) -> E::Out; } -#[cfg(feature = "postgres_backend")] +#[cfg(all(feature = "postgres_backend", feature = "serde_json"))] define_sql_function! { /// Converts the given json value to pretty-printed, indented text /// @@ -1906,6 +1907,7 @@ define_sql_function! { fn jsonb_pretty>(e: E) -> E::Out; } +#[cfg(all(feature = "postgres_backend", feature = "serde_json"))] define_sql_function! { /// Deletes all object fields that have null values from the given JSON value, recursively. /// @@ -1952,6 +1954,7 @@ define_sql_function! { fn json_strip_nulls(json: E) -> E; } +#[cfg(all(feature = "postgres_backend", feature = "serde_json"))] define_sql_function! { /// Deletes all object fields that have null values from the given JSON value, recursively. /// @@ -1999,7 +2002,7 @@ define_sql_function! { fn jsonb_strip_nulls(jsonb: E) -> E; } -#[cfg(feature = "postgres_backend")] +#[cfg(all(feature = "postgres_backend", feature = "serde_json"))] define_sql_function! { /// Returns the number of elements in the top-level JSON array /// @@ -2042,7 +2045,7 @@ define_sql_function! { fn json_array_length>(json: E) -> E::Out; } -#[cfg(feature = "postgres_backend")] +#[cfg(all(feature = "postgres_backend", feature = "serde_json"))] define_sql_function! { /// Returns the number of elements in the top-level JSON array /// @@ -2085,7 +2088,7 @@ define_sql_function! { fn jsonb_array_length>(jsonb: E) -> E::Out; } -#[cfg(feature = "postgres_backend")] +#[cfg(all(feature = "postgres_backend", feature = "serde_json"))] define_sql_function! { /// Builds a JSON object out of a text array. The array must have an even number of members, /// in which case they are taken as alternating key/value pairs. This function also has a form that @@ -2141,7 +2144,7 @@ define_sql_function! { ) -> Arr::Out; } -#[cfg(feature = "postgres_backend")] +#[cfg(all(feature = "postgres_backend", feature = "serde_json"))] define_sql_function! { /// This form of jsonb_object takes keys and values pairwise from two separate arrays. /// In all other respects it is identical to the one-argument form. diff --git a/diesel/src/pg/expression/helper_types.rs b/diesel/src/pg/expression/helper_types.rs index efc1d8e68975..84ae4bc93755 100644 --- a/diesel/src/pg/expression/helper_types.rs +++ b/diesel/src/pg/expression/helper_types.rs @@ -1,9 +1,14 @@ use crate::dsl::{AsExpr, AsExprOf, SqlTypeOf}; use crate::expression::grouped::Grouped; -use crate::expression::Expression; -use crate::pg::expression::expression_methods::private::{JsonIndex, JsonRemoveIndex}; -use crate::pg::types::sql_types::Array; use crate::sql_types::{Inet, Integer, VarChar}; +#[cfg(all(feature = "postgres_backend", feature = "serde_json"))] +use crate::{ + expression::Expression, + pg::{ + expression::expression_methods::{JsonIndex, JsonRemoveIndex}, + types::sql_types::Array, + }, +}; /// The return type of [`lhs.ilike(rhs)`](super::expression_methods::PgTextExpressionMethods::ilike) #[cfg(feature = "postgres_backend")] @@ -193,27 +198,30 @@ pub type Diff = DifferenceNet; pub type ConcatJsonb = crate::dsl::Concat; /// The return type of [`lsh.has_key(rhs)`](super::expression_methods::PgJsonbExpressionMethods::has_key) -#[cfg(feature = "postgres_backend")] +#[cfg(all(feature = "postgres_backend", feature = "serde_json"))] pub type HasKeyJsonb = Grouped>>; #[doc(hidden)] // needed for `#[auto_type]` +#[cfg(all(feature = "postgres_backend", feature = "serde_json"))] pub type HasKey = HasKeyJsonb; /// The return type of [`lsh.has_any_key(rhs)`](super::expression_methods::PgJsonbExpressionMethods::has_any_key) -#[cfg(feature = "postgres_backend")] +#[cfg(all(feature = "postgres_backend", feature = "serde_json"))] pub type HasAnyKeyJsonb = Grouped>>>; #[doc(hidden)] // needed for `#[auto_type]` +#[cfg(all(feature = "postgres_backend", feature = "serde_json"))] pub type HasAnyKey = HasAnyKeyJsonb; /// The return type of [`lsh.has_all_keys(rhs)`](super::expression_methods::PgJsonbExpressionMethods::has_all_keys) -#[cfg(feature = "postgres_backend")] +#[cfg(all(feature = "postgres_backend", feature = "serde_json"))] pub type HasAllKeysJsonb = Grouped>>>; #[doc(hidden)] // needed for `#[auto_type]` +#[cfg(all(feature = "postgres_backend", feature = "serde_json"))] pub type HasAllKeys = HasAllKeysJsonb; #[doc(hidden)] @@ -233,11 +241,12 @@ pub type Index = super::operators::ArrayIndex = Index; /// The return type of [`lhs.remove(rhs)`](super::expression_methods::PgJsonbExpressionMethods::remove) -#[cfg(feature = "postgres_backend")] +#[cfg(all(feature = "postgres_backend", feature = "serde_json"))] pub type RemoveFromJsonb = Grouped>>; #[doc(hidden)] // needed for `#[auto_type]` +#[cfg(all(feature = "postgres_backend", feature = "serde_json"))] pub type Remove = RemoveFromJsonb< Lhs, ::Expression, @@ -245,11 +254,12 @@ pub type Remove = RemoveFromJsonb< >; /// The return type of [`lhs.retrieve_as_object(rhs)`](super::expression_methods::PgAnyJsonExpressionMethods::retrieve_as_object) -#[cfg(feature = "postgres_backend")] +#[cfg(all(feature = "postgres_backend", feature = "serde_json"))] pub type RetrieveAsObjectJson = Grouped>>; #[doc(hidden)] // needed for `#[auto_type]` +#[cfg(all(feature = "postgres_backend", feature = "serde_json"))] pub type RetrieveAsObject = RetrieveAsObjectJson< Lhs, ::Expression, @@ -257,11 +267,12 @@ pub type RetrieveAsObject = RetrieveAsObjectJson< >; /// The return type of [`lhs.retrieve_as_text(rhs)`](super::expression_methods::PgAnyJsonExpressionMethods::retrieve_as_text) -#[cfg(feature = "postgres_backend")] +#[cfg(all(feature = "postgres_backend", feature = "serde_json"))] pub type RetrieveAsTextJson = Grouped>>; #[doc(hidden)] // needed for `#[auto_type]` +#[cfg(all(feature = "postgres_backend", feature = "serde_json"))] pub type RetrieveAsText = RetrieveAsTextJson< Lhs, ::Expression, @@ -269,27 +280,30 @@ pub type RetrieveAsText = RetrieveAsTextJson< >; /// The return type of [`lhs.retrieve_by_path_as_object(rhs)`](super::expression_methods::PgAnyJsonExpressionMethods::retrieve_by_path_as_object) -#[cfg(feature = "postgres_backend")] +#[cfg(all(feature = "postgres_backend", feature = "serde_json"))] pub type RetrieveByPathAsObjectJson = Grouped>>>; #[doc(hidden)] // needed for `#[auto_type]` +#[cfg(all(feature = "postgres_backend", feature = "serde_json"))] pub type RetrieveByPathAsObject = RetrieveByPathAsObjectJson; /// The return type of [`lhs.retrieve_by_path_as_text(rhs)`](super::expression_methods::PgAnyJsonExpressionMethods::retrieve_by_path_as_text) -#[cfg(feature = "postgres_backend")] +#[cfg(all(feature = "postgres_backend", feature = "serde_json"))] pub type RetrieveByPathAsTextJson = Grouped>>>; #[doc(hidden)] // needed for `#[auto_type]` +#[cfg(all(feature = "postgres_backend", feature = "serde_json"))] pub type RetrieveByPathAsText = RetrieveByPathAsTextJson; /// The return type of [`lhs.remove_by_path(rhs)`](super::expression_methods::PgJsonbExpressionMethods::remove_by_path) -#[cfg(feature = "postgres_backend")] +#[cfg(all(feature = "postgres_backend", feature = "serde_json"))] pub type RemoveByPathFromJsonb = Grouped>>>; #[doc(hidden)] // needed for `#[auto_type]` +#[cfg(all(feature = "postgres_backend", feature = "serde_json"))] pub type RemoveByPath = RemoveByPathFromJsonb; #[doc(hidden)] @@ -474,67 +488,67 @@ pub type array_sample = super::functions::array_sample, A, N> /// Return type of [`to_json(element)`](super::functions::to_json()) #[allow(non_camel_case_types)] -#[cfg(feature = "postgres_backend")] +#[cfg(all(feature = "postgres_backend", feature = "serde_json"))] pub type to_json = super::functions::to_json, E>; /// Return type of [`to_jsonb(element)`](super::functions::to_jsonb()) #[allow(non_camel_case_types)] -#[cfg(feature = "postgres_backend")] +#[cfg(all(feature = "postgres_backend", feature = "serde_json"))] pub type to_jsonb = super::functions::to_jsonb, E>; /// Return type of [`json_object(text_array)`](super::functions::json_object()) #[allow(non_camel_case_types)] -#[cfg(feature = "postgres_backend")] +#[cfg(all(feature = "postgres_backend", feature = "serde_json"))] pub type json_object = super::functions::json_object, A>; /// Return type of [`json_object_with_keys_and_values(text_array, text_array)`](super::functions::json_object_with_keys_and_values()) #[allow(non_camel_case_types)] -#[cfg(feature = "postgres_backend")] +#[cfg(all(feature = "postgres_backend", feature = "serde_json"))] pub type json_object_with_keys_and_values = super::functions::json_object_with_keys_and_values, SqlTypeOf, K, V>; /// Return type of [`json_typeof(json)`](super::functions::json_typeof()) #[allow(non_camel_case_types)] -#[cfg(feature = "postgres_backend")] +#[cfg(all(feature = "postgres_backend", feature = "serde_json"))] pub type json_typeof = super::functions::json_typeof, E>; /// Return type of [`jsonb_typeof(jsonb)`](super::functions::jsonb_typeof()) #[allow(non_camel_case_types)] -#[cfg(feature = "postgres_backend")] +#[cfg(all(feature = "postgres_backend", feature = "serde_json"))] pub type jsonb_typeof = super::functions::jsonb_typeof, E>; /// Return type of [`jsonb_pretty(jsonb)`](super::functions::jsonb_pretty()) #[allow(non_camel_case_types)] -#[cfg(feature = "postgres_backend")] +#[cfg(all(feature = "postgres_backend", feature = "serde_json"))] pub type jsonb_pretty = super::functions::jsonb_pretty, E>; /// Return type of [`json_strip_nulls(json)`](super::functions::json_strip_nulls()) #[allow(non_camel_case_types)] -#[cfg(feature = "postgres_backend")] +#[cfg(all(feature = "postgres_backend", feature = "serde_json"))] pub type json_strip_nulls = super::functions::json_strip_nulls, E>; /// Return type of [`jsonb_strip_nulls(jsonb)`](super::functions::jsonb_strip_nulls()) #[allow(non_camel_case_types)] -#[cfg(feature = "postgres_backend")] +#[cfg(all(feature = "postgres_backend", feature = "serde_json"))] pub type jsonb_strip_nulls = super::functions::jsonb_strip_nulls, E>; /// Return type of [`json_array_length(json)`](super::functions::json_array_length()) #[allow(non_camel_case_types)] -#[cfg(feature = "postgres_backend")] +#[cfg(all(feature = "postgres_backend", feature = "serde_json"))] pub type json_array_length = super::functions::json_array_length, E>; /// Return type of [`jsonb_array_length(jsonb)`](super::functions::jsonb_array_length()) #[allow(non_camel_case_types)] -#[cfg(feature = "postgres_backend")] +#[cfg(all(feature = "postgres_backend", feature = "serde_json"))] pub type jsonb_array_length = super::functions::jsonb_array_length, E>; /// Return type of [`jsonb_object(text_array)`](super::functions::jsonb_object()) #[allow(non_camel_case_types)] -#[cfg(feature = "postgres_backend")] +#[cfg(all(feature = "postgres_backend", feature = "serde_json"))] pub type jsonb_object = super::functions::jsonb_object, A>; /// Return type of [`jsonb_object_with_keys_and_values(text_array, text_array)`](super::functions::jsonb_object_with_keys_and_values()) #[allow(non_camel_case_types)] -#[cfg(feature = "postgres_backend")] +#[cfg(all(feature = "postgres_backend", feature = "serde_json"))] pub type jsonb_object_with_keys_and_values = super::functions::jsonb_object_with_keys_and_values, SqlTypeOf, K, V>; diff --git a/diesel/src/pg/expression/operators.rs b/diesel/src/pg/expression/operators.rs index 4bc660ecb09c..ffbfd586bb08 100644 --- a/diesel/src/pg/expression/operators.rs +++ b/diesel/src/pg/expression/operators.rs @@ -5,9 +5,9 @@ use crate::pg::Pg; use crate::query_builder::update_statement::changeset::AssignmentTarget; use crate::query_builder::{AstPass, QueryFragment, QueryId}; use crate::query_dsl::positional_order_dsl::{IntoPositionalOrderExpr, PositionalOrderExpr}; -use crate::sql_types::{ - Array, Bigint, Bool, DieselNumericOps, Inet, Integer, Jsonb, SqlType, Text, -}; +use crate::sql_types::{Array, Bigint, Bool, DieselNumericOps, Inet, Integer, SqlType}; +#[cfg(feature = "serde_json")] +use crate::sql_types::{Jsonb, Text}; use crate::{Column, QueryResult}; __diesel_infix_operator!(IsDistinctFrom, " IS DISTINCT FROM ", ConstantNullability Bool, backend: Pg); @@ -30,25 +30,34 @@ infix_operator!(IsContainedByNetLoose, " <<= ", backend: Pg); infix_operator!(AndNet, " & ", Inet, backend: Pg); infix_operator!(OrNet, " | ", Inet, backend: Pg); infix_operator!(DifferenceNet, " - ", Bigint, backend: Pg); +#[cfg(feature = "serde_json")] infix_operator!(HasKeyJsonb, " ? ", backend: Pg); +#[cfg(feature = "serde_json")] infix_operator!(HasAnyKeyJsonb, " ?| ", backend: Pg); +#[cfg(feature = "serde_json")] infix_operator!(HasAllKeysJsonb, " ?& ", backend: Pg); infix_operator!(RangeAdjacent, " -|- ", backend: Pg); +#[cfg(feature = "serde_json")] infix_operator!(RemoveFromJsonb, " - ", Jsonb, backend: Pg); +#[cfg(feature = "serde_json")] __diesel_infix_operator!( RetrieveAsObjectJson, " -> ", __diesel_internal_SameResultAsInput, backend: Pg ); +#[cfg(feature = "serde_json")] infix_operator!(RetrieveAsTextJson, " ->> ", Text, backend: Pg); +#[cfg(feature = "serde_json")] __diesel_infix_operator!( RetrieveByPathAsObjectJson, " #> ", __diesel_internal_SameResultAsInput, backend: Pg ); +#[cfg(feature = "serde_json")] infix_operator!(RetrieveByPathAsTextJson, " #>> ", Text, backend: Pg); +#[cfg(feature = "serde_json")] infix_operator!(RemoveByPathFromJsonb, " #-", Jsonb, backend: Pg); __diesel_infix_operator!(