diesel/sqlite/expression/
functions.rs

1//! SQLite specific functions
2#[cfg(doc)]
3use crate::expression::functions::aggregate_expressions::AggregateExpressionMethods;
4use crate::expression::functions::declare_sql_function;
5use crate::expression_methods::json_expression_methods::private::JsonOrNullableJsonOrJsonbOrNullableJsonb;
6use crate::sql_types::*;
7use crate::sqlite::expression::expression_methods::BinaryOrNullableBinary;
8use crate::sqlite::expression::expression_methods::JsonOrNullableJson;
9use crate::sqlite::expression::expression_methods::MaybeNullableValue;
10use crate::sqlite::expression::expression_methods::NotBlob;
11use crate::sqlite::expression::expression_methods::TextOrNullableText;
12use crate::sqlite::expression::expression_methods::TextOrNullableTextOrBinaryOrNullableBinary;
13use crate::sqlite::expression::functions::helper::CombinedNullableValue;
14
15#[cfg(feature = "sqlite")]
16#[allow(unused_imports)]
#[doc(hidden)]
mod return_type_helpers {
    #[doc(inline)]
    pub use super::__json_return_type::*;
    #[doc(inline)]
    pub use super::__jsonb_return_type::*;
    #[doc(inline)]
    pub use super::__json_array_length_return_type::*;
    #[doc(inline)]
    pub use super::__json_array_length_with_path_return_type::*;
    #[doc(inline)]
    pub use super::__json_error_position_return_type::*;
    #[doc(inline)]
    pub use super::__json_pretty_return_type::*;
    #[doc(inline)]
    pub use super::__json_pretty_with_indentation_return_type::*;
    #[doc(inline)]
    pub use super::__json_valid_return_type::*;
    #[doc(inline)]
    pub use super::__json_valid_with_flags_return_type::*;
    #[doc(inline)]
    pub use super::__json_type_return_type::*;
    #[doc(inline)]
    pub use super::__json_type_with_path_return_type::*;
    #[doc(inline)]
    pub use super::__json_quote_return_type::*;
    #[doc(inline)]
    pub use super::__json_group_array_return_type::*;
    #[doc(inline)]
    pub use super::__jsonb_group_array_return_type::*;
    #[doc(inline)]
    pub use super::__json_object_return_types::*;
    #[doc(inline)]
    pub use super::__jsonb_object_return_types::*;
    #[doc(inline)]
    pub use super::__json_group_object_return_type::*;
    #[doc(inline)]
    pub use super::__jsonb_group_object_return_type::*;
    #[doc(inline)]
    pub use super::__json_array_return_types::*;
    #[doc(inline)]
    pub use super::__jsonb_array_return_types::*;
    #[doc(inline)]
    pub use super::__json_remove_return_types::*;
    #[doc(inline)]
    pub use super::__jsonb_remove_return_types::*;
    #[doc(inline)]
    pub use super::__json_patch_return_type::*;
    #[doc(inline)]
    pub use super::__jsonb_patch_return_type::*;
}#[declare_sql_function(generate_return_type_helpers = true)]
17#[backends(crate::sqlite::Sqlite)]
18extern "SQL" {
19    /// Verifies that its argument is a valid JSON string or JSONB blob and returns a minified
20    /// version of that JSON string with all unnecessary whitespace removed.
21    ///
22    /// # Example
23    ///
24    /// ```rust
25    /// # include!("../../doctest_setup.rs");
26    /// #
27    /// # fn main() {
28    /// #     #[cfg(feature = "serde_json")]
29    /// #     run_test().unwrap();
30    /// # }
31    /// #
32    /// # #[cfg(feature = "serde_json")]
33    /// # fn run_test() -> QueryResult<()> {
34    /// #     use diesel::dsl::json;
35    /// #     use serde_json::{json, Value};
36    /// #     use diesel::sql_types::{Text, Nullable};
37    /// #     let connection = &mut establish_connection();
38    ///
39    /// let result = diesel::select(json::<Text, _>(r#"{"a": "b", "c": 1}"#))
40    ///     .get_result::<Value>(connection)?;
41    ///
42    /// assert_eq!(json!({"a":"b","c":1}), result);
43    ///
44    /// let result = diesel::select(json::<Text, _>(r#"{ "this" : "is", "a": [ "test" ] }"#))
45    ///     .get_result::<Value>(connection)?;
46    ///
47    /// assert_eq!(json!({"a":["test"],"this":"is"}), result);
48    ///
49    /// let result = diesel::select(json::<Nullable<Text>, _>(None::<&str>))
50    ///     .get_result::<Option<Value>>(connection)?;
51    ///
52    /// assert!(result.is_none());
53    ///
54    /// #     Ok(())
55    /// # }
56    /// ```
57    fn json<E: TextOrNullableText + MaybeNullableValue<Json>>(e: E) -> E::Out;
58
59    /// The jsonb(X) function returns the binary JSONB representation of the JSON provided as argument X.
60    ///
61    /// This function requires at least SQLite 3.45 or newer
62    ///
63    /// # Example
64    ///
65    /// ```rust
66    /// # include!("../../doctest_setup.rs");
67    /// #
68    /// # fn main() {
69    /// #     #[cfg(feature = "serde_json")]
70    /// #     run_test().unwrap();
71    /// # }
72    /// #
73    /// # #[cfg(feature = "serde_json")]
74    /// # fn run_test() -> QueryResult<()> {
75    /// #     use diesel::dsl::{sql, jsonb};
76    /// #     use serde_json::{json, Value};
77    /// #     use diesel::sql_types::{Text, Binary, Nullable};
78    /// #     let connection = &mut establish_connection();
79    /// #     assert_version!(connection, 3, 45, 0);
80    ///
81    /// let result = diesel::select(jsonb::<Binary, _>(br#"{"a": "b", "c": 1}"#))
82    ///     .get_result::<Value>(connection)?;
83    ///
84    /// assert_eq!(json!({"a": "b", "c": 1}), result);
85    ///
86    /// let result = diesel::select(jsonb::<Binary, _>(br#"{"this":"is","a":["test"]}"#))
87    ///     .get_result::<Value>(connection)?;
88    ///
89    /// assert_eq!(json!({"this":"is","a":["test"]}), result);
90    ///
91    /// let result = diesel::select(jsonb::<Nullable<Binary>, _>(None::<Vec<u8>>))
92    ///     .get_result::<Option<Value>>(connection)?;
93    ///
94    /// assert!(result.is_none());
95    ///
96    /// #     Ok(())
97    /// # }
98    /// ```
99    fn jsonb<E: BinaryOrNullableBinary + MaybeNullableValue<Jsonb>>(e: E) -> E::Out;
100
101    /// The json_array_length(X) function returns the number of elements in the JSON array X,
102    /// or 0 if X is some kind of JSON value other than an array.
103    /// Errors are thrown if either X is not well-formed JSON or if P is not a well-formed path.
104    ///
105    /// This function requires at least SQLite 3.46 or newer
106    ///
107    /// # Example
108    ///
109    /// ```rust
110    /// # include!("../../doctest_setup.rs");
111    /// #
112    /// # fn main() {
113    /// #     #[cfg(feature = "serde_json")]
114    /// #     run_test().unwrap();
115    /// # }
116    /// #
117    /// # #[cfg(feature = "serde_json")]
118    /// # fn run_test() -> QueryResult<()> {
119    /// #     use diesel::dsl::{sql, json_array_length};
120    /// #     use serde_json::{json, Value};
121    /// #     use diesel::sql_types::{Json, Jsonb, Text, Nullable};
122    /// #     let connection = &mut establish_connection();
123    /// #     assert_version!(connection, 3, 46, 0);
124    ///
125    /// let result = diesel::select(json_array_length::<Json, _>(json!([1,2,3,4])))
126    ///     .get_result::<i32>(connection)?;
127    ///
128    /// assert_eq!(4, result);
129    ///
130    /// let result = diesel::select(json_array_length::<Json, _>(json!({"one":[1,2,3]})))
131    ///     .get_result::<i32>(connection)?;
132    ///
133    /// assert_eq!(0, result);
134    ///
135    /// let result = diesel::select(json_array_length::<Nullable<Json>, _>(None::<Value>))
136    ///     .get_result::<Option<i32>>(connection)?;
137    ///
138    /// assert_eq!(None, result);
139    ///
140    /// let result = diesel::select(json_array_length::<Jsonb, _>(json!([1,2,3,4])))
141    ///     .get_result::<i32>(connection)?;
142    ///
143    /// assert_eq!(4, result);
144    ///
145    /// let result = diesel::select(json_array_length::<Jsonb, _>(json!({"one":[1,2,3]})))
146    ///     .get_result::<i32>(connection)?;
147    ///
148    /// assert_eq!(0, result);
149    ///
150    /// let result = diesel::select(json_array_length::<Nullable<Jsonb>, _>(None::<Value>))
151    ///     .get_result::<Option<i32>>(connection)?;
152    ///
153    /// assert_eq!(None, result);
154    ///
155    /// #     Ok(())
156    /// # }
157    /// ```
158    #[cfg(feature = "sqlite")]
159    fn json_array_length<
160        J: JsonOrNullableJsonOrJsonbOrNullableJsonb + MaybeNullableValue<Integer>,
161    >(
162        j: J,
163    ) -> J::Out;
164
165    /// The json_array_length(X) function returns the number of elements in the JSON array X,
166    /// or 0 if X is some kind of JSON value other than an array.
167    /// The json_array_length(X,P) locates the array at path P within X and returns the length of that array,
168    /// or 0 if path P locates an element in X that is not a JSON array,
169    /// and NULL if path P does not locate any element of X.
170    /// Errors are thrown if either X is not well-formed JSON or if P is not a well-formed path.
171    ///
172    /// This function requires at least SQLite 3.46 or newer
173    ///
174    /// # Example
175    ///
176    /// ```rust
177    /// # include!("../../doctest_setup.rs");
178    /// #
179    /// # fn main() {
180    /// #     #[cfg(feature = "serde_json")]
181    /// #     run_test().unwrap();
182    /// # }
183    /// #
184    /// # #[cfg(feature = "serde_json")]
185    /// # fn run_test() -> QueryResult<()> {
186    /// #     use diesel::dsl::{sql, json_array_length_with_path};
187    /// #     use serde_json::{json, Value};
188    /// #     use diesel::sql_types::{Json, Jsonb, Text, Nullable};
189    /// #     let connection = &mut establish_connection();
190    /// #     assert_version!(connection, 3, 46, 0);
191    ///
192    /// let result = diesel::select(json_array_length_with_path::<Json, _, _>(json!([1,2,3,4]), "$"))
193    ///     .get_result::<Option<i32>>(connection)?;
194    ///
195    /// assert_eq!(Some(4), result);
196    ///
197    /// let result = diesel::select(json_array_length_with_path::<Json, _, _>(json!([1,2,3,4]), "$[2]"))
198    ///     .get_result::<Option<i32>>(connection)?;
199    ///
200    /// assert_eq!(Some(0), result);
201    ///
202    /// let result = diesel::select(json_array_length_with_path::<Json, _, _>(json!({"one":[1,2,3]}), "$.one"))
203    ///     .get_result::<Option<i32>>(connection)?;
204    ///
205    /// assert_eq!(Some(3), result);
206    ///
207    /// let result = diesel::select(json_array_length_with_path::<Nullable<Json>, _, _>(json!({"one":[1,2,3]}), "$.two"))
208    ///     .get_result::<Option<i32>>(connection)?;
209    ///
210    /// assert_eq!(None, result);
211    ///
212    /// let result = diesel::select(json_array_length_with_path::<Jsonb, _, _>(json!([1,2,3,4]), "$"))
213    ///     .get_result::<Option<i32>>(connection)?;
214    ///
215    /// assert_eq!(Some(4), result);
216    ///
217    /// let result = diesel::select(json_array_length_with_path::<Jsonb, _, _>(json!([1,2,3,4]), "$[2]"))
218    ///     .get_result::<Option<i32>>(connection)?;
219    ///
220    /// assert_eq!(Some(0), result);
221    ///
222    /// let result = diesel::select(json_array_length_with_path::<Jsonb, _, _>(json!({"one":[1,2,3]}), "$.one"))
223    ///     .get_result::<Option<i32>>(connection)?;
224    ///
225    /// assert_eq!(Some(3), result);
226    ///
227    /// let result = diesel::select(json_array_length_with_path::<Nullable<Jsonb>, _, _>(json!({"one":[1,2,3]}), "$.two"))
228    ///     .get_result::<Option<i32>>(connection)?;
229    ///
230    /// assert_eq!(None, result);
231    ///
232    /// #     Ok(())
233    /// # }
234    /// ```
235    #[sql_name = "json_array_length"]
236    #[cfg(feature = "sqlite")]
237    fn json_array_length_with_path<J: JsonOrNullableJsonOrJsonbOrNullableJsonb + SingleValue>(
238        j: J,
239        path: Text,
240    ) -> Nullable<Integer>;
241
242    /// The json_error_position(X) function returns 0 if the input X is a well-formed JSON or JSON5 string.
243    /// If the input X contains one or more syntax errors, then this function returns the character position of the first syntax error.
244    /// The left-most character is position 1.
245    ///
246    /// If the input X is a BLOB, then this routine returns 0 if X is a well-formed JSONB blob. If the return value is positive,
247    /// then it represents the approximate 1-based position in the BLOB of the first detected error.
248    ///
249    /// This function requires at least SQLite 3.46 or newer
250    ///
251    /// # Example
252    ///
253    /// ```rust
254    /// # include!("../../doctest_setup.rs");
255    /// #
256    /// # fn main() {
257    /// #     #[cfg(feature = "serde_json")]
258    /// #     run_test().unwrap();
259    /// # }
260    /// #
261    /// # #[cfg(feature = "serde_json")]
262    /// # fn run_test() -> QueryResult<()> {
263    /// #     use diesel::dsl::{sql, json_error_position};
264    /// #     use diesel::sql_types::{Binary, Text, Nullable};
265    /// #     let connection = &mut establish_connection();
266    /// #     assert_version!(connection, 3, 46, 0);
267    ///
268    /// let result = diesel::select(json_error_position::<Text, _>(r#"{"a": "b", "c": 1}"#))
269    ///     .get_result::<i32>(connection)?;
270    ///
271    /// assert_eq!(0, result);
272    ///
273    /// let result = diesel::select(json_error_position::<Text, _>(r#"{"a": b", "c": 1}"#))
274    ///     .get_result::<i32>(connection)?;
275    ///
276    /// assert_eq!(7, result);
277    ///
278    /// let json5 = r#"
279    ///     {
280    ///         // A traditional message.
281    ///         message: 'hello world',
282    ///
283    ///         // A number for some reason.
284    ///         n: 42,
285    ///     }
286    /// "#;
287    /// let result =
288    ///     diesel::select(json_error_position::<Text, _>(json5)).get_result::<i32>(connection)?;
289    ///
290    /// assert_eq!(0, result);
291    ///
292    /// let json5_with_error = r#"
293    ///     {
294    ///         // A traditional message.
295    ///         message: hello world',
296    ///
297    ///         // A number for some reason.
298    ///         n: 42,
299    ///     }
300    /// "#;
301    /// let result = diesel::select(json_error_position::<Text, _>(json5_with_error))
302    ///     .get_result::<i32>(connection)?;
303    ///
304    /// assert_eq!(59, result);
305    ///
306    /// let result = diesel::select(json_error_position::<Nullable<Text>, _>(None::<&str>))
307    ///     .get_result::<Option<i32>>(connection)?;
308    ///
309    /// assert_eq!(None, result);
310    ///
311    /// let result = diesel::select(json_error_position::<Binary, _>(br#"{"a": "b", "c": 1}"#))
312    ///     .get_result::<i32>(connection)?;
313    ///
314    /// assert_eq!(0, result);
315    ///
316    /// let result = diesel::select(json_error_position::<Binary, _>(br#"{"a": b", "c": 1}"#))
317    ///     .get_result::<i32>(connection)?;
318    ///
319    /// assert_eq!(7, result);
320    ///
321    /// let result = diesel::select(json_error_position::<Nullable<Binary>, _>(None::<Vec<u8>>))
322    ///     .get_result::<Option<i32>>(connection)?;
323    ///
324    /// assert_eq!(None, result);
325    ///
326    /// #     Ok(())
327    /// # }
328    /// ```
329    #[cfg(feature = "sqlite")]
330    fn json_error_position<
331        X: TextOrNullableTextOrBinaryOrNullableBinary + MaybeNullableValue<Integer>,
332    >(
333        x: X,
334    ) -> X::Out;
335
336    /// Converts the given json value to pretty-printed, indented text
337    ///
338    /// This function requires at least SQLite 3.46 or newer
339    ///
340    /// # Example
341    ///
342    /// ```rust
343    /// # include!("../../doctest_setup.rs");
344    /// #
345    /// # fn main() {
346    /// #     #[cfg(feature = "serde_json")]
347    /// #     run_test().unwrap();
348    /// # }
349    /// #
350    /// # #[cfg(feature = "serde_json")]
351    /// # fn run_test() -> QueryResult<()> {
352    /// #     use diesel::dsl::{sql, json_pretty};
353    /// #     use serde_json::{json, Value};
354    /// #     use diesel::sql_types::{Text, Json, Jsonb, Nullable};
355    /// #     let connection = &mut establish_connection();
356    /// #     assert_version!(connection, 3, 46, 0);
357    ///
358    /// let result = diesel::select(json_pretty::<Json, _>(json!([{"f1":1,"f2":null},2,null,3])))
359    ///     .get_result::<String>(connection)?;
360    ///
361    /// assert_eq!(r#"[
362    ///     {
363    ///         "f1": 1,
364    ///         "f2": null
365    ///     },
366    ///     2,
367    ///     null,
368    ///     3
369    /// ]"#, result);
370    ///
371    /// let result = diesel::select(json_pretty::<Json, _>(json!({"a": 1, "b": "cd"})))
372    ///     .get_result::<String>(connection)?;
373    ///
374    /// assert_eq!(r#"{
375    ///     "a": 1,
376    ///     "b": "cd"
377    /// }"#, result);
378    ///
379    /// let result = diesel::select(json_pretty::<Json, _>(json!("abc")))
380    ///     .get_result::<String>(connection)?;
381    ///
382    /// assert_eq!(r#""abc""#, result);
383    ///
384    /// let result = diesel::select(json_pretty::<Json, _>(json!(22)))
385    ///     .get_result::<String>(connection)?;
386    ///
387    /// assert_eq!(r#"22"#, result);
388    ///
389    /// let result = diesel::select(json_pretty::<Json, _>(json!(false)))
390    ///     .get_result::<String>(connection)?;
391    ///
392    /// assert_eq!(r#"false"#, result);
393    ///
394    /// let result = diesel::select(json_pretty::<Json, _>(json!(null)))
395    ///     .get_result::<String>(connection)?;
396    ///
397    /// assert_eq!(r#"null"#, result);
398    ///
399    /// let result = diesel::select(json_pretty::<Json, _>(json!({})))
400    ///     .get_result::<String>(connection)?;
401    ///
402    /// assert_eq!(r#"{}"#, result);
403    ///
404    /// let result = diesel::select(json_pretty::<Nullable<Json>, _>(None::<Value>))
405    ///     .get_result::<Option<String>>(connection)?;
406    ///
407    /// assert!(result.is_none());
408    ///
409    /// let result = diesel::select(json_pretty::<Jsonb, _>(json!([{"f1":1,"f2":null},2,null,3])))
410    ///     .get_result::<String>(connection)?;
411    ///
412    /// assert_eq!(r#"[
413    ///     {
414    ///         "f1": 1,
415    ///         "f2": null
416    ///     },
417    ///     2,
418    ///     null,
419    ///     3
420    /// ]"#, result);
421    ///
422    /// let result = diesel::select(json_pretty::<Jsonb, _>(json!({"a": 1, "b": "cd"})))
423    ///     .get_result::<String>(connection)?;
424    ///
425    /// assert_eq!(r#"{
426    ///     "a": 1,
427    ///     "b": "cd"
428    /// }"#, result);
429    ///
430    /// let result = diesel::select(json_pretty::<Jsonb, _>(json!("abc")))
431    ///     .get_result::<String>(connection)?;
432    ///
433    /// assert_eq!(r#""abc""#, result);
434    ///
435    /// let result = diesel::select(json_pretty::<Jsonb, _>(json!(22)))
436    ///     .get_result::<String>(connection)?;
437    ///
438    /// assert_eq!(r#"22"#, result);
439    ///
440    /// let result = diesel::select(json_pretty::<Jsonb, _>(json!(false)))
441    ///     .get_result::<String>(connection)?;
442    ///
443    /// assert_eq!(r#"false"#, result);
444    ///
445    /// let result = diesel::select(json_pretty::<Jsonb, _>(json!(null)))
446    ///     .get_result::<String>(connection)?;
447    ///
448    /// assert_eq!(r#"null"#, result);
449    ///
450    /// let result = diesel::select(json_pretty::<Jsonb, _>(json!({})))
451    ///     .get_result::<String>(connection)?;
452    ///
453    /// assert_eq!(r#"{}"#, result);
454    ///
455    /// let result = diesel::select(json_pretty::<Nullable<Jsonb>, _>(None::<Value>))
456    ///     .get_result::<Option<String>>(connection)?;
457    ///
458    /// assert!(result.is_none());
459    /// #     Ok(())
460    /// # }
461    /// ```
462    fn json_pretty<J: JsonOrNullableJsonOrJsonbOrNullableJsonb + MaybeNullableValue<Text>>(
463        j: J,
464    ) -> J::Out;
465
466    /// Converts the given json value to pretty-printed, indented text
467    ///
468    /// This function requires at least SQLite 3.46 or newer
469    ///
470    /// # Example
471    ///
472    /// ```rust
473    /// # include!("../../doctest_setup.rs");
474    /// #
475    /// # fn main() {
476    /// #     #[cfg(feature = "serde_json")]
477    /// #     run_test().unwrap();
478    /// # }
479    /// #
480    /// # #[cfg(feature = "serde_json")]
481    /// # fn run_test() -> QueryResult<()> {
482    /// #     use diesel::dsl::{sql, json_pretty_with_indentation};
483    /// #     use serde_json::{json, Value};
484    /// #     use diesel::sql_types::{Text, Json, Jsonb, Nullable};
485    /// #     let connection = &mut establish_connection();
486    /// #     assert_version!(connection, 3, 46, 0);
487    ///
488    /// let result = diesel::select(json_pretty_with_indentation::<Json, _, _>(json!([{"f1":1,"f2":null},2,null,3]), "  "))
489    ///     .get_result::<String>(connection)?;
490    ///
491    /// assert_eq!(r#"[
492    ///   {
493    ///     "f1": 1,
494    ///     "f2": null
495    ///   },
496    ///   2,
497    ///   null,
498    ///   3
499    /// ]"#, result);
500    ///
501    /// let result = diesel::select(json_pretty_with_indentation::<Json, _, _>(json!([{"f1":1,"f2":null},2,null,3]), None::<&str>))
502    ///     .get_result::<String>(connection)?;
503    ///
504    /// assert_eq!(r#"[
505    ///     {
506    ///         "f1": 1,
507    ///         "f2": null
508    ///     },
509    ///     2,
510    ///     null,
511    ///     3
512    /// ]"#, result);
513    ///
514    /// let result = diesel::select(json_pretty_with_indentation::<Json, _, _>(json!({"a": 1, "b": "cd"}), "  "))
515    ///     .get_result::<String>(connection)?;
516    ///
517    /// assert_eq!(r#"{
518    ///   "a": 1,
519    ///   "b": "cd"
520    /// }"#, result);
521    ///
522    /// let result = diesel::select(json_pretty_with_indentation::<Json, _, _>(json!("abc"), "  "))
523    ///     .get_result::<String>(connection)?;
524    ///
525    /// assert_eq!(r#""abc""#, result);
526    ///
527    /// let result = diesel::select(json_pretty_with_indentation::<Json, _, _>(json!(22), "  "))
528    ///     .get_result::<String>(connection)?;
529    ///
530    /// assert_eq!(r#"22"#, result);
531    ///
532    /// let result = diesel::select(json_pretty_with_indentation::<Json, _, _>(json!(false), None::<&str>))
533    ///     .get_result::<String>(connection)?;
534    ///
535    /// assert_eq!(r#"false"#, result);
536    ///
537    /// let result = diesel::select(json_pretty_with_indentation::<Json, _, _>(json!(null), None::<&str>))
538    ///     .get_result::<String>(connection)?;
539    ///
540    /// assert_eq!(r#"null"#, result);
541    ///
542    /// let result = diesel::select(json_pretty_with_indentation::<Json, _, _>(json!({}), "  "))
543    ///     .get_result::<String>(connection)?;
544    ///
545    /// assert_eq!(r#"{}"#, result);
546    ///
547    /// let result = diesel::select(json_pretty_with_indentation::<Nullable<Json>, _, _>(None::<Value>, None::<&str>))
548    ///     .get_result::<Option<String>>(connection)?;
549    ///
550    /// assert!(result.is_none());
551    ///
552    /// let result = diesel::select(json_pretty_with_indentation::<Jsonb, _, _>(json!([{"f1":1,"f2":null},2,null,3]), "  "))
553    ///     .get_result::<String>(connection)?;
554    ///
555    /// assert_eq!(r#"[
556    ///   {
557    ///     "f1": 1,
558    ///     "f2": null
559    ///   },
560    ///   2,
561    ///   null,
562    ///   3
563    /// ]"#, result);
564    ///
565    /// let result = diesel::select(json_pretty_with_indentation::<Jsonb, _, _>(json!([{"f1":1,"f2":null},2,null,3]), None::<&str>))
566    ///     .get_result::<String>(connection)?;
567    ///
568    /// assert_eq!(r#"[
569    ///     {
570    ///         "f1": 1,
571    ///         "f2": null
572    ///     },
573    ///     2,
574    ///     null,
575    ///     3
576    /// ]"#, result);
577    ///
578    /// let result = diesel::select(json_pretty_with_indentation::<Jsonb, _, _>(json!({"a": 1, "b": "cd"}), "  "))
579    ///     .get_result::<String>(connection)?;
580    ///
581    /// assert_eq!(r#"{
582    ///   "a": 1,
583    ///   "b": "cd"
584    /// }"#, result);
585    ///
586    /// let result = diesel::select(json_pretty_with_indentation::<Jsonb, _, _>(json!("abc"), "  "))
587    ///     .get_result::<String>(connection)?;
588    ///
589    /// assert_eq!(r#""abc""#, result);
590    ///
591    /// let result = diesel::select(json_pretty_with_indentation::<Jsonb, _, _>(json!(22), "  "))
592    ///     .get_result::<String>(connection)?;
593    ///
594    /// assert_eq!(r#"22"#, result);
595    ///
596    /// let result = diesel::select(json_pretty_with_indentation::<Jsonb, _, _>(json!(false), None::<&str>))
597    ///     .get_result::<String>(connection)?;
598    ///
599    /// assert_eq!(r#"false"#, result);
600    ///
601    /// let result = diesel::select(json_pretty_with_indentation::<Jsonb, _, _>(json!(null), None::<&str>))
602    ///     .get_result::<String>(connection)?;
603    ///
604    /// assert_eq!(r#"null"#, result);
605    ///
606    /// let result = diesel::select(json_pretty_with_indentation::<Jsonb, _, _>(json!({}), "  "))
607    ///     .get_result::<String>(connection)?;
608    ///
609    /// assert_eq!(r#"{}"#, result);
610    ///
611    /// let result = diesel::select(json_pretty_with_indentation::<Nullable<Jsonb>, _, _>(None::<Value>, None::<&str>))
612    ///     .get_result::<Option<String>>(connection)?;
613    ///
614    /// assert!(result.is_none());
615    ///
616    /// #     Ok(())
617    /// # }
618    /// ```
619    #[sql_name = "json_pretty"]
620    fn json_pretty_with_indentation<
621        J: JsonOrNullableJsonOrJsonbOrNullableJsonb + MaybeNullableValue<Text>,
622    >(
623        j: J,
624        indentation: Nullable<Text>,
625    ) -> J::Out;
626
627    /// Returns  `true`  if the argument is well-formed JSON, or returns  `false`  if is not well-formed.
628    ///
629    /// This function requires at least SQLite 3.46 or newer
630    ///
631    /// # Example
632    ///
633    /// ```rust
634    /// # include!("../../doctest_setup.rs");
635    /// #
636    /// # fn main() {
637    /// #     #[cfg(feature = "serde_json")]
638    /// #     run_test().unwrap();
639    /// # }
640    /// #
641    /// # #[cfg(feature = "serde_json")]
642    /// # fn run_test() -> QueryResult<()> {
643    /// #     use diesel::dsl::{sql, json_valid};
644    /// #     use serde_json::{json, Value};
645    /// #     use diesel::sql_types::{Text, Json, Jsonb, Nullable};
646    /// #     let connection = &mut establish_connection();
647    /// #     assert_version!(connection, 3, 46, 0);
648    ///
649    /// let result = diesel::select(json_valid::<Json, _>(json!({"x":35})))
650    ///     .get_result::<bool>(connection)?;
651    ///
652    /// assert_eq!(true, result);
653    ///
654    /// let result = diesel::select(json_valid::<Nullable<Json>, _>(None::<serde_json::Value>))
655    ///     .get_result::<Option<bool>>(connection)?;
656    ///
657    /// assert_eq!(None, result);
658    ///
659    /// # Ok(())
660    /// # }
661    /// ```
662    #[sql_name = "json_valid"]
663    #[cfg(feature = "sqlite")]
664    fn json_valid<J: JsonOrNullableJson + MaybeNullableValue<Bool>>(j: J) -> J::Out;
665
666    /// The json_valid(X,Y) function returns 1 if the argument X is well-formed JSON, or returns 0 if X is not well-formed.
667    /// The Y parameter is an integer bitmask that defines what is meant by "well-formed".
668    ///
669    /// The following bits of Y are currently defined:
670    /// - 0x01 → The input is text that strictly complies with canonical RFC-8259 JSON, without any extensions.
671    /// - 0x02 → The input is text that is JSON with JSON5 extensions.
672    /// - 0x04 → The input is a BLOB that superficially appears to be JSONB.
673    /// - 0x08 → The input is a BLOB that strictly conforms to the internal JSONB format.
674    ///
675    /// By combining bits, the following useful values of Y can be derived:
676    /// - 1 → X is RFC-8259 JSON text
677    /// - 2 → X is JSON5 text
678    /// - 4 → X is probably JSONB
679    /// - 5 → X is RFC-8259 JSON text or JSONB
680    /// - 6 → X is JSON5 text or JSONB (recommended for most use cases)
681    /// - 8 → X is strictly conforming JSONB
682    /// - 9 → X is RFC-8259 or strictly conforming JSONB
683    /// - 10 → X is JSON5 or strictly conforming JSONB
684    ///
685    /// The Y parameter must be between 1 and 15 (inclusive), or an error is raised.
686    ///
687    /// If either X or Y inputs are NULL, then the function returns NULL.
688    ///
689    /// This function requires at least SQLite 3.46 or newer
690    ///
691    /// # Example
692    ///
693    /// ```rust
694    /// # include!("../../doctest_setup.rs");
695    /// #
696    /// # fn main() {
697    /// #     #[cfg(feature = "serde_json")]
698    /// #     run_test().unwrap();
699    /// # }
700    /// #
701    /// # #[cfg(feature = "serde_json")]
702    /// # fn run_test() -> QueryResult<()> {
703    /// #     use diesel::dsl::{sql, json_valid_with_flags};
704    /// #     use diesel::sqlite::JsonValidFlag;
705    /// #     use serde_json::{json, Value};
706    /// #     use diesel::sql_types::{Text, Json, Jsonb, Nullable};
707    /// #     let connection = &mut establish_connection();
708    /// #     assert_version!(connection, 3, 46, 0);
709    ///
710    /// // Standard RFC-8259 JSON
711    /// let result = diesel::select(json_valid_with_flags::<Text, _, _>(r#"{"x":35}"#, JsonValidFlag::Rfc8259Json))
712    ///     .get_result::<bool>(connection)?;
713    /// assert_eq!(true, result);
714    ///
715    /// // JSON5 not valid as RFC-8259
716    /// let result = diesel::select(json_valid_with_flags::<Text, _, _>(r#"{x:35}"#, JsonValidFlag::Rfc8259Json))
717    ///     .get_result::<bool>(connection)?;
718    /// assert_eq!(false, result);
719    ///
720    /// // JSON5 valid with JSON5 flag
721    /// let result = diesel::select(json_valid_with_flags::<Text, _, _>(r#"{x:35}"#, JsonValidFlag::Json5OrJsonb))
722    ///     .get_result::<bool>(connection)?;
723    /// assert_eq!(true, result);
724    ///
725    /// // Invalid JSON
726    /// let result = diesel::select(json_valid_with_flags::<Text, _, _>(r#"{"x":35"#, JsonValidFlag::Rfc8259Json))
727    ///     .get_result::<bool>(connection)?;
728    /// assert_eq!(false, result);
729    ///
730    /// // NULL input returns NULL
731    /// let result = diesel::select(json_valid_with_flags::<Nullable<Text>, _, _>(None::<&str>, JsonValidFlag::Rfc8259Json))
732    ///     .get_result::<Option<bool>>(connection)?;
733    /// assert_eq!(None, result);
734    ///
735    /// # Ok(())
736    /// # }
737    /// ```
738    #[sql_name = "json_valid"]
739    #[cfg(feature = "sqlite")]
740    fn json_valid_with_flags<
741        X: TextOrNullableTextOrBinaryOrNullableBinary + SingleValue + MaybeNullableValue<Bool>,
742    >(
743        x: X,
744        flags: crate::sqlite::types::JsonValidFlags,
745    ) -> X::Out;
746
747    /// The json_type(X) function returns the "type" of the outermost element of X.
748    /// The "type" returned by json_type() is one of the following SQL text values:
749    /// 'null', 'true', 'false', 'integer', 'real', 'text', 'array', or 'object'.
750    ///
751    /// This function requires at least SQLite 3.38 or newer
752    ///
753    /// # Example
754    ///
755    /// ```rust
756    /// # include!("../../doctest_setup.rs");
757    /// #
758    /// # fn main() {
759    /// #     #[cfg(feature = "serde_json")]
760    /// #     run_test().unwrap();
761    /// # }
762    /// #
763    /// # #[cfg(feature = "serde_json")]
764    /// # fn run_test() -> QueryResult<()> {
765    /// #     use diesel::dsl::{sql, json_type};
766    /// #     use serde_json::{json, Value};
767    /// #     use diesel::sql_types::{Text, Json, Jsonb, Nullable};
768    /// #     let connection = &mut establish_connection();
769    /// #     assert_version!(connection, 3, 38, 0);
770    ///
771    /// let result = diesel::select(json_type::<Json, _>(json!({"a": [2, 3.5, true, false, null, "x"]})))
772    ///     .get_result::<String>(connection)?;
773    ///
774    /// assert_eq!("object", result);
775    ///
776    /// let result = diesel::select(json_type::<Jsonb, _>(json!({"a": [2, 3.5, true, false, null, "x"]})))
777    ///     .get_result::<String>(connection)?;
778    ///
779    /// assert_eq!("object", result);
780    ///
781    /// let result = diesel::select(json_type::<Nullable<Json>, _>(None::<serde_json::Value>))
782    ///     .get_result::<Option<String>>(connection)?;
783    ///
784    /// assert_eq!(None, result);
785    ///
786    /// # Ok(())
787    /// # }
788    /// ```
789    #[sql_name = "json_type"]
790    #[cfg(feature = "sqlite")]
791    fn json_type<J: JsonOrNullableJsonOrJsonbOrNullableJsonb + MaybeNullableValue<Text>>(
792        j: J,
793    ) -> J::Out;
794
795    /// The json_type(X,P) function returns the "type" of the element in X that is selected by path P.
796    /// If the path P in json_type(X,P) selects an element that does not exist in X, then this function returns NULL.
797    ///
798    /// This function requires at least SQLite 3.38 or newer
799    ///
800    /// # Example
801    ///
802    /// ```rust
803    /// # include!("../../doctest_setup.rs");
804    /// #
805    /// # fn main() {
806    /// #     #[cfg(feature = "serde_json")]
807    /// #     run_test().unwrap();
808    /// # }
809    /// #
810    /// # #[cfg(feature = "serde_json")]
811    /// # fn run_test() -> QueryResult<()> {
812    /// #     use diesel::dsl::{sql, json_type_with_path};
813    /// #     use serde_json::{json, Value};
814    /// #     use diesel::sql_types::{Text, Json, Jsonb, Nullable};
815    /// #     let connection = &mut establish_connection();
816    /// #     assert_version!(connection, 3, 38, 0);
817    ///
818    /// let json_value = json!({"a": [2, 3.5, true, false, null, "x"]});
819    ///
820    /// let result = diesel::select(json_type_with_path::<Json, _, _>(json_value.clone(), "$.a"))
821    ///     .get_result::<Option<String>>(connection)?;
822    ///
823    /// assert_eq!(Some("array".to_string()), result);
824    ///
825    /// let result = diesel::select(json_type_with_path::<Json, _, _>(json_value.clone(), "$.a[0]"))
826    ///     .get_result::<Option<String>>(connection)?;
827    ///
828    /// assert_eq!(Some("integer".to_string()), result);
829    ///
830    /// let result = diesel::select(json_type_with_path::<Json, _, _>(json_value.clone(), "$.a[1]"))
831    ///     .get_result::<Option<String>>(connection)?;
832    ///
833    /// assert_eq!(Some("real".to_string()), result);
834    ///
835    /// let result = diesel::select(json_type_with_path::<Json, _, _>(json_value.clone(), "$.a[2]"))
836    ///     .get_result::<Option<String>>(connection)?;
837    ///
838    /// assert_eq!(Some("true".to_string()), result);
839    ///
840    /// let result = diesel::select(json_type_with_path::<Json, _, _>(json_value.clone(), "$.a[6]"))
841    ///     .get_result::<Option<String>>(connection)?;
842    ///
843    /// assert_eq!(None, result);
844    ///
845    /// let result = diesel::select(json_type_with_path::<Jsonb, _, _>(json_value.clone(), "$.a"))
846    ///     .get_result::<Option<String>>(connection)?;
847    ///
848    /// assert_eq!(Some("array".to_string()), result);
849    ///
850    /// let result = diesel::select(json_type_with_path::<Nullable<Json>, _, _>(None::<serde_json::Value>, "$.a"))
851    ///     .get_result::<Option<String>>(connection)?;
852    ///
853    /// assert_eq!(None, result);
854    ///
855    /// # Ok(())
856    /// # }
857    /// ```
858    #[sql_name = "json_type"]
859    #[cfg(feature = "sqlite")]
860    fn json_type_with_path<J: JsonOrNullableJsonOrJsonbOrNullableJsonb + SingleValue>(
861        j: J,
862        path: Text,
863    ) -> Nullable<Text>;
864
865    /// The json_quote(X) function converts the SQL value X (a number or a string) into its corresponding JSON
866    /// representation. If X is a JSON value returned by another JSON function, then this function is a no-op.
867    ///
868    /// This function requires at least SQLite 3.38 or newer
869    ///
870    /// # Example
871    ///
872    /// ```rust
873    /// # include!("../../doctest_setup.rs");
874    /// #
875    /// # fn main() {
876    /// #     #[cfg(feature = "serde_json")]
877    /// #     run_test().unwrap();
878    /// # }
879    /// #
880    /// # #[cfg(feature = "serde_json")]
881    /// # fn run_test() -> QueryResult<()> {
882    /// #     use diesel::dsl::{sql, json_quote};
883    /// #     use serde_json::{json, Value};
884    /// #     use diesel::sql_types::{Text, Json, Integer, Float, Double, Nullable};
885    /// #     let connection = &mut establish_connection();
886    /// #     assert_version!(connection, 3, 38, 0);
887    ///
888    /// let result = diesel::select(json_quote::<Integer, _>(42))
889    ///     .get_result::<Value>(connection)?;
890    /// assert_eq!(json!(42), result);
891    ///
892    /// let result = diesel::select(json_quote::<Text, _>("verdant"))
893    ///     .get_result::<Value>(connection)?;
894    /// assert_eq!(json!("verdant"), result);
895    ///
896    /// let result = diesel::select(json_quote::<Text, _>("[1]"))
897    ///     .get_result::<Value>(connection)?;
898    /// assert_eq!(json!("[1]"), result);
899    ///
900    /// let result = diesel::select(json_quote::<Nullable<Text>, _>(None::<&str>))
901    ///     .get_result::<Value>(connection)?;
902    /// assert_eq!(json!(null), result);
903    ///
904    /// let result = diesel::select(json_quote::<Double, _>(3.14159))
905    ///     .get_result::<Value>(connection)?;
906    /// assert_eq!(json!(3.14159), result);
907    ///
908    /// let result = diesel::select(json_quote::<Json, _>(json!([1])))
909    ///     .get_result::<Value>(connection)?;
910    // assert_eq!(json!([1]), result);
911    ///
912    ///
913    /// # Ok(())
914    /// # }
915    /// ```
916    #[sql_name = "json_quote"]
917    #[cfg(feature = "sqlite")]
918    fn json_quote<J: SqlType + SingleValue>(j: J) -> Json;
919
920    /// The `json_group_array(X)` function is an aggregate SQL function that returns a JSON array comprised of
921    /// all X values in the aggregation.
922    ///
923    /// ## Aggregate Function Expression
924    ///
925    /// This function can be used as aggregate expression. See [`AggregateExpressionMethods`] for details.
926    ///
927    /// # Examples
928    ///
929    /// ## Normal function usage
930    ///
931    /// ```rust
932    /// # include!("../../doctest_setup.rs");
933    /// #
934    /// # fn main() {
935    /// #     #[cfg(feature = "serde_json")]
936    /// #     run_test().unwrap();
937    /// # }
938    /// #
939    /// # #[cfg(feature = "serde_json")]
940    /// # fn run_test() -> QueryResult<()> {
941    /// #     use diesel::dsl::*;
942    /// #     use schema::animals::dsl::*;
943    /// #     use serde_json::json;
944    /// #
945    /// #     let connection = &mut establish_connection();
946    /// #
947    /// let result = animals
948    ///     .select(json_group_array(species))
949    ///     .get_result::<serde_json::Value>(connection)?;
950    /// assert_eq!(result, json!(["dog", "spider"]));
951    ///
952    /// let result = animals
953    ///     .select(json_group_array(legs))
954    ///     .get_result::<serde_json::Value>(connection)?;
955    /// assert_eq!(result, json!([4, 8]));
956    ///
957    /// let result = animals
958    ///     .select(json_group_array(name))
959    ///     .get_result::<serde_json::Value>(connection)?;
960    /// assert_eq!(result, json!(["Jack", null]));
961    ///
962    /// # Ok(())
963    /// # }
964    /// ```
965    /// ## Aggregate function expression
966    ///
967    /// ```rust
968    /// # include!("../../doctest_setup.rs");
969    /// #
970    /// # fn main() {
971    /// #     #[cfg(feature = "serde_json")]
972    /// #     run_test().unwrap();
973    /// # }
974    /// #
975    /// # #[cfg(feature = "serde_json")]
976    /// # fn run_test() -> QueryResult<()> {
977    /// #     use diesel::dsl::*;
978    /// #     use schema::animals::dsl::*;
979    /// #     use serde_json::json;
980    /// #
981    /// #     let connection = &mut establish_connection();
982    /// #
983    /// let result = animals
984    ///     .select(json_group_array(species).aggregate_filter(legs.lt(8)))
985    ///     .get_result::<serde_json::Value>(connection)?;
986    /// assert_eq!(result, json!(["dog"]));
987    ///
988    /// # Ok(())
989    /// # }
990    /// ```
991    ///
992    /// # See also
993    /// - [`jsonb_group_array`](jsonb_group_array()) will return data in JSONB format instead of JSON.
994    /// - [`json_group_object`](json_group_object()) will return JSON object instead of array.
995    #[cfg(feature = "sqlite")]
996    #[aggregate]
997    fn json_group_array<E: SqlType + SingleValue>(elements: E) -> Json;
998
999    /// The `jsonb_group_array(X)` function is an aggregate SQL function that returns a JSONB array comprised of
1000    /// all X values in the aggregation.
1001    ///
1002    /// ## Aggregate Function Expression
1003    ///
1004    /// This function can be used as aggregate expression. See [`AggregateExpressionMethods`] for details.
1005    ///
1006    /// # Examples
1007    ///
1008    /// ## Normal function usage
1009    ///
1010    /// ```rust
1011    /// # include!("../../doctest_setup.rs");
1012    /// #
1013    /// # fn main() {
1014    /// #     #[cfg(feature = "serde_json")]
1015    /// #     run_test().unwrap();
1016    /// # }
1017    /// #
1018    /// # #[cfg(feature = "serde_json")]
1019    /// # fn run_test() -> QueryResult<()> {
1020    /// #     use diesel::dsl::*;
1021    /// #     use schema::animals::dsl::*;
1022    /// #     use serde_json::json;
1023    /// #
1024    /// #     let connection = &mut establish_connection();
1025    /// #
1026    /// let result = animals
1027    ///     .select(json_group_array(species))
1028    ///     .get_result::<serde_json::Value>(connection)?;
1029    /// assert_eq!(result, json!(["dog", "spider"]));
1030    ///
1031    /// let result = animals
1032    ///     .select(json_group_array(legs))
1033    ///     .get_result::<serde_json::Value>(connection)?;
1034    /// assert_eq!(result, json!([4, 8]));
1035    ///
1036    /// let result = animals
1037    ///     .select(json_group_array(name))
1038    ///     .get_result::<serde_json::Value>(connection)?;
1039    /// assert_eq!(result, json!(["Jack", null]));
1040    ///
1041    /// # Ok(())
1042    /// # }
1043    /// ```
1044    ///
1045    /// ## Aggregate function expression
1046    ///
1047    /// ```rust
1048    /// # include!("../../doctest_setup.rs");
1049    /// #
1050    /// # fn main() {
1051    /// #     #[cfg(feature = "serde_json")]
1052    /// #     run_test().unwrap();
1053    /// # }
1054    /// #
1055    /// # #[cfg(feature = "serde_json")]
1056    /// # fn run_test() -> QueryResult<()> {
1057    /// #     use diesel::dsl::*;
1058    /// #     use schema::animals::dsl::*;
1059    /// #     use serde_json::json;
1060    /// #
1061    /// #     let connection = &mut establish_connection();
1062    /// #
1063    /// let result = animals
1064    ///     .select(json_group_array(species).aggregate_filter(legs.lt(8)))
1065    ///     .get_result::<serde_json::Value>(connection)?;
1066    /// assert_eq!(result, json!(["dog"]));
1067    ///
1068    /// # Ok(())
1069    /// # }
1070    /// ```
1071    ///
1072    /// # See also
1073    /// - [`json_group_array`](json_group_array()) will return data in JSON format instead of JSONB.
1074    /// - [`jsonb_group_object`](jsonb_group_object()) will return JSONB object instead of array.
1075    #[cfg(feature = "sqlite")]
1076    #[aggregate]
1077    fn jsonb_group_array<E: SqlType + SingleValue>(elements: E) -> Jsonb;
1078
1079    /// The `json_object()` SQL function accepts zero or more pairs of arguments and returns a
1080    /// well-formed JSON object composed from those pairs. The first argument of each pair is the
1081    /// label (key) and the second argument is the value. If any argument to `json_object()` is a
1082    /// BLOB then an error is thrown.
1083    ///
1084    /// An argument with SQL type TEXT is normally converted into a quoted JSON string even if the
1085    /// input text is well-formed JSON. However, if the argument is the direct result from another
1086    /// JSON function, then it is treated as JSON and all of its JSON type information and
1087    /// substructure is preserved. This allows calls to `json_object()` and `json_array()` to be
1088    /// nested. The [`json()`] function can also be used to force strings to be recognized as JSON.
1089    ///
1090    /// This function requires at least SQLite 3.38 or newer
1091    ///
1092    /// # Examples
1093    ///
1094    /// ```rust
1095    /// # include!("../../doctest_setup.rs");
1096    /// #
1097    /// # fn main() {
1098    /// #     #[cfg(feature = "serde_json")]
1099    /// #     run_test().unwrap();
1100    /// # }
1101    /// #
1102    /// # #[cfg(feature = "serde_json")]
1103    /// # fn run_test() -> QueryResult<()> {
1104    /// #     use diesel::dsl::*;
1105    /// #     use diesel::sql_types::{Text, Integer};
1106    /// #     use serde_json::json;
1107    /// #
1108    /// #     let connection = &mut establish_connection();
1109    /// #     assert_version!(connection, 3, 38, 0);
1110    /// #
1111    /// let result = diesel::select(json_object_0()).get_result::<serde_json::Value>(connection)?;
1112    /// assert_eq!(json!({}), result);
1113    ///
1114    /// let result = diesel::select(json_object_1::<Text, Integer, _, _>("a", 2))
1115    ///     .get_result::<serde_json::Value>(connection)?;
1116    /// assert_eq!(json!({"a": 2}), result);
1117    ///
1118    /// let result = diesel::select(
1119    ///     json_object_2::<Text, Integer, Text, Text, _, _, _, _>("a", 2, "c", "{e:5}")
1120    /// )
1121    /// .get_result::<serde_json::Value>(connection)?;
1122    /// assert_eq!(json!({"a": 2, "c": "{e:5}"}), result);
1123    ///
1124    /// let result = diesel::select(
1125    ///     json_object_2::<Text, Integer, Text, Json, _, _, _, _>("a", 2, "c", json_object_1::<Text, Integer, _, _>("e", 5))
1126    /// )
1127    /// .get_result::<serde_json::Value>(connection)?;
1128    /// assert_eq!(json!({"a": 2, "c": {"e": 5}}), result);
1129    /// #
1130    /// # Ok(())
1131    /// # }
1132    /// ```
1133    #[cfg(feature = "sqlite")]
1134    #[variadic(2)]
1135    fn json_object<K: NotBlob<IsNull = is_nullable::NotNull>, V: NotBlob>(key: K, value: V)
1136        -> Json;
1137
1138    /// The `jsonb_object()` SQL function works just like the [`json_object()`](json_object_1())
1139    /// function except that the generated object is returned in SQLite's private binary JSONB
1140    /// format rather than in the standard RFC 8259 text format.
1141    ///
1142    /// This function requires at least SQLite 3.38 or newer
1143    ///
1144    /// # Examples
1145    ///
1146    /// ```rust
1147    /// # include!("../../doctest_setup.rs");
1148    /// #
1149    /// # fn main() {
1150    /// #     #[cfg(feature = "serde_json")]
1151    /// #     run_test().unwrap();
1152    /// # }
1153    /// #
1154    /// # #[cfg(feature = "serde_json")]
1155    /// # fn run_test() -> QueryResult<()> {
1156    /// #     use diesel::dsl::*;
1157    /// #     use diesel::sql_types::{Text, Integer};
1158    /// #     use serde_json::json;
1159    /// #
1160    /// #     let connection = &mut establish_connection();
1161    /// #     assert_version!(connection, 3, 38, 0);
1162    /// #
1163    /// let result = diesel::select(jsonb_object_0()).get_result::<serde_json::Value>(connection)?;
1164    /// assert_eq!(json!({}), result);
1165    ///
1166    /// let result = diesel::select(jsonb_object_1::<Text, Integer, _, _>("a", 2))
1167    ///     .get_result::<serde_json::Value>(connection)?;
1168    /// assert_eq!(json!({"a": 2}), result);
1169    ///
1170    /// let result = diesel::select(
1171    ///     jsonb_object_2::<Text, Integer, Text, Text, _, _, _, _>("a", 2, "c", "{e:5}")
1172    /// )
1173    /// .get_result::<serde_json::Value>(connection)?;
1174    /// assert_eq!(json!({"a": 2, "c": "{e:5}"}), result);
1175    /// #
1176    /// # Ok(())
1177    /// # }
1178    /// ```
1179    #[cfg(feature = "sqlite")]
1180    #[variadic(2)]
1181    fn jsonb_object<K: NotBlob<IsNull = is_nullable::NotNull>, V: NotBlob>(
1182        key: K,
1183        value: V,
1184    ) -> Jsonb;
1185
1186    /// The json_group_object(NAME,VALUE) function returns a JSON object comprised of all NAME/VALUE pairs in
1187    /// the aggregation.
1188    ///
1189    /// A potential edge case in this function arises when `names` contains duplicate elements.
1190    /// In such case, the result will include all duplicates (e.g., `{"key": 1, "key": 2, "key": 3}`).
1191    /// Note that any duplicate entries in the resulting JSON will be removed during deserialization.
1192    ///
1193    /// This function requires at least SQLite 3.38 or newer
1194    ///
1195    /// ## Aggregate Function Expression
1196    ///
1197    /// This function can be used as aggregate expression. See [`AggregateExpressionMethods`] for details.
1198    ///
1199    /// # Examples
1200    ///
1201    /// ## Normal function usage
1202    ///
1203    /// ```rust
1204    /// # include!("../../doctest_setup.rs");
1205    /// #
1206    /// # fn main() {
1207    /// #     #[cfg(feature = "serde_json")]
1208    /// #     run_test().unwrap();
1209    /// # }
1210    /// #
1211    /// # #[cfg(feature = "serde_json")]
1212    /// # fn run_test() -> QueryResult<()> {
1213    /// #     use diesel::dsl::*;
1214    /// #     use diesel::sql_types::Text;
1215    /// #     use serde_json::json;
1216    /// #     use schema::animals::dsl::*;
1217    /// #
1218    /// #     let connection = &mut establish_connection();
1219    /// #     assert_version!(connection, 3, 38, 0);
1220    /// #
1221    /// let result = animals.select(json_group_object(species, name)).get_result::<serde_json::Value>(connection)?;
1222    /// assert_eq!(json!({"dog":"Jack","spider":null}), result);
1223    /// #
1224    /// # Ok(())
1225    /// # }
1226    /// ```
1227    ///
1228    /// ## Aggregate function expression
1229    ///
1230    /// ```rust
1231    /// # include!("../../doctest_setup.rs");
1232    /// #
1233    /// # fn main() {
1234    /// #     #[cfg(feature = "serde_json")]
1235    /// #     run_test().unwrap();
1236    /// # }
1237    /// #
1238    /// # #[cfg(feature = "serde_json")]
1239    /// # fn run_test() -> QueryResult<()> {
1240    /// #     use diesel::dsl::*;
1241    /// #     use diesel::sql_types::Text;
1242    /// #     use serde_json::json;
1243    /// #     use schema::animals::dsl::*;
1244    /// #
1245    /// #     let connection = &mut establish_connection();
1246    /// #
1247    /// #     let version = diesel::select(sql::<Text>("sqlite_version();"))
1248    /// #         .get_result::<String>(connection)?;
1249    /// #
1250    /// #     let version_components: Vec<&str> = version.split('.').collect();
1251    /// #     let major: u32 = version_components[0].parse().unwrap();
1252    /// #     let minor: u32 = version_components[1].parse().unwrap();
1253    /// #
1254    /// #     if major < 3 || minor < 38 {
1255    /// #         println!("SQLite version is too old, skipping the test.");
1256    /// #         return Ok(());
1257    /// #     }
1258    /// #
1259    /// let result = animals.select(json_group_object(species, name).aggregate_filter(legs.lt(8))).get_result::<serde_json::Value>(connection)?;
1260    /// assert_eq!(json!({"dog":"Jack"}), result);
1261    /// #
1262    /// # Ok(())
1263    /// # }
1264    /// ```
1265    ///
1266    /// # See also
1267    /// - [`jsonb_group_object`](jsonb_group_object()) will return data in JSONB format instead of JSON.
1268    /// - [`json_group_array`](json_group_array()) will return JSON array instead of object.
1269    #[cfg(feature = "sqlite")]
1270    #[aggregate]
1271    fn json_group_object<
1272        N: SqlType<IsNull = is_nullable::NotNull> + SingleValue,
1273        V: SqlType + SingleValue,
1274    >(
1275        names: N,
1276        values: V,
1277    ) -> Json;
1278
1279    /// The jsonb_group_object(NAME,VALUE) function returns a JSONB object comprised of all NAME/VALUE pairs in
1280    /// the aggregation.
1281    ///
1282    /// A potential edge case in this function arises when `names` contains duplicate elements.
1283    /// In such case, the result will include all duplicates (e.g., `{"key": 1, "key": 2, "key": 3}`).
1284    /// Note that any duplicate entries in the resulting JSONB will be removed during deserialization.
1285    ///
1286    /// This function requires at least SQLite 3.38 or newer
1287    ///
1288    /// ## Aggregate Function Expression
1289    ///
1290    /// This function can be used as aggregate expression. See [`AggregateExpressionMethods`] for details.
1291    ///
1292    /// # Examples
1293    ///
1294    /// ## Normal function usage
1295    ///
1296    /// ```rust
1297    /// # include!("../../doctest_setup.rs");
1298    /// #
1299    /// # fn main() {
1300    /// #     #[cfg(feature = "serde_json")]
1301    /// #     run_test().unwrap();
1302    /// # }
1303    /// #
1304    /// # #[cfg(feature = "serde_json")]
1305    /// # fn run_test() -> QueryResult<()> {
1306    /// #     use diesel::dsl::*;
1307    /// #     use diesel::sql_types::Text;
1308    /// #     use serde_json::json;
1309    /// #     use schema::animals::dsl::*;
1310    /// #
1311    /// #     let connection = &mut establish_connection();
1312    /// #     assert_version!(connection, 3, 38, 0);
1313    /// #
1314    /// let result = animals.select(jsonb_group_object(species, name)).get_result::<serde_json::Value>(connection)?;
1315    /// assert_eq!(json!({"dog":"Jack","spider":null}), result);
1316    /// #
1317    /// # Ok(())
1318    /// # }
1319    /// ```
1320    ///
1321    /// ## Aggregate function expression
1322    ///
1323    /// ```rust
1324    /// # include!("../../doctest_setup.rs");
1325    /// #
1326    /// # fn main() {
1327    /// #     #[cfg(feature = "serde_json")]
1328    /// #     run_test().unwrap();
1329    /// # }
1330    /// #
1331    /// # #[cfg(feature = "serde_json")]
1332    /// # fn run_test() -> QueryResult<()> {
1333    /// #     use diesel::dsl::*;
1334    /// #     use diesel::sql_types::Text;
1335    /// #     use serde_json::json;
1336    /// #     use schema::animals::dsl::*;
1337    /// #
1338    /// #     let connection = &mut establish_connection();
1339    /// #
1340    /// #     let version = diesel::select(sql::<Text>("sqlite_version();"))
1341    /// #         .get_result::<String>(connection)?;
1342    /// #
1343    /// #     let version_components: Vec<&str> = version.split('.').collect();
1344    /// #     let major: u32 = version_components[0].parse().unwrap();
1345    /// #     let minor: u32 = version_components[1].parse().unwrap();
1346    /// #
1347    /// #     if major < 3 || minor < 38 {
1348    /// #         println!("SQLite version is too old, skipping the test.");
1349    /// #         return Ok(());
1350    /// #     }
1351    /// #
1352    /// let result = animals.select(jsonb_group_object(species, name).aggregate_filter(legs.lt(8))).get_result::<serde_json::Value>(connection)?;
1353    /// assert_eq!(json!({"dog":"Jack"}), result);
1354    /// #
1355    /// # Ok(())
1356    /// # }
1357    /// ```
1358    ///
1359    /// # See also
1360    /// - [`json_group_object`](jsonb_group_array()) will return data in JSON format instead of JSONB.
1361    /// - [`jsonb_group_array`](jsonb_group_array()) will return JSONB array instead of object.
1362    #[cfg(feature = "sqlite")]
1363    #[aggregate]
1364    fn jsonb_group_object<
1365        N: SqlType<IsNull = is_nullable::NotNull> + SingleValue,
1366        V: SqlType + SingleValue,
1367    >(
1368        names: N,
1369        values: V,
1370    ) -> Jsonb;
1371
1372    /// The `json_array()` SQL function accepts zero or more arguments and returns a well-formed JSON array
1373    /// that is composed from those arguments. Note that arguments of type BLOB will not be accepted by this
1374    /// function.
1375    ///
1376    /// An argument with SQL type TEXT is normally converted into a quoted JSON string. However, if the
1377    /// argument is the output from another json function, then it is stored as JSON. This allows calls to
1378    /// `json_array()` and `json_object()` to be nested. The [`json()`] function can also be used to force
1379    /// strings to be recognized as JSON.
1380    ///
1381    /// This function requires at least SQLite 3.38 or newer
1382    ///
1383    /// # Examples
1384    ///
1385    /// ```rust
1386    /// # include!("../../doctest_setup.rs");
1387    /// #
1388    /// # fn main() {
1389    /// #     #[cfg(feature = "serde_json")]
1390    /// #     run_test().unwrap();
1391    /// # }
1392    /// #
1393    /// # #[cfg(feature = "serde_json")]
1394    /// # fn run_test() -> QueryResult<()> {
1395    /// #     use diesel::dsl::*;
1396    /// #     use diesel::sql_types::{Text, Double};
1397    /// #     use serde_json::json;
1398    /// #
1399    /// #     let connection = &mut establish_connection();
1400    /// #     assert_version!(connection, 3, 38, 0);
1401    /// #
1402    /// let result = diesel::select(json_array_0()).get_result::<serde_json::Value>(connection)?;
1403    /// assert_eq!(json!([]), result);
1404    ///
1405    /// let result = diesel::select(json_array_1::<Text, _>("abc"))
1406    ///     .get_result::<serde_json::Value>(connection)?;
1407    /// assert_eq!(json!(["abc"]), result);
1408    ///
1409    /// let result = diesel::select(json_array_2::<Text, Double, _, _>("abc", 3.1415))
1410    ///     .get_result::<serde_json::Value>(connection)?;
1411    /// assert_eq!(json!(["abc", 3.1415]), result);
1412    /// #
1413    /// # Ok(())
1414    /// # }
1415    /// ```
1416    #[cfg(feature = "sqlite")]
1417    #[variadic(1)]
1418    fn json_array<V: NotBlob>(value: V) -> Json;
1419
1420    /// The `jsonb_array()` SQL function accepts zero or more arguments and returns a well-formed JSON array
1421    /// that is composed from those arguments. Note that arguments of type BLOB will not be accepted by this
1422    /// function.
1423    ///
1424    /// An argument with SQL type TEXT is normally converted into a quoted JSON string. However, if the
1425    /// argument is the output from another json function, then it is stored as JSON. This allows calls to
1426    /// `jsonb_array()` and `jsonb_object()` to be nested. The [`json()`] function can also be used to force
1427    /// strings to be recognized as JSON.
1428    ///
1429    /// This function works just like the [`json_array()`](json_array_1()) function except that it returns the
1430    /// constructed JSON array in the SQLite's private JSONB format rather than in the standard RFC 8259 text
1431    /// format.
1432    ///
1433    /// This function requires at least SQLite 3.38 or newer
1434    ///
1435    /// # Examples
1436    ///
1437    /// ```rust
1438    /// # include!("../../doctest_setup.rs");
1439    /// #
1440    /// # fn main() {
1441    /// #     #[cfg(feature = "serde_json")]
1442    /// #     run_test().unwrap();
1443    /// # }
1444    /// #
1445    /// # #[cfg(feature = "serde_json")]
1446    /// # fn run_test() -> QueryResult<()> {
1447    /// #     use diesel::dsl::*;
1448    /// #     use diesel::sql_types::{Text, Double};
1449    /// #     use serde_json::json;
1450    /// #
1451    /// #     let connection = &mut establish_connection();
1452    /// #     assert_version!(connection, 3, 38, 0);
1453    /// #
1454    /// let result = diesel::select(jsonb_array_0()).get_result::<serde_json::Value>(connection)?;
1455    /// assert_eq!(json!([]), result);
1456    ///
1457    /// let result = diesel::select(jsonb_array_1::<Text, _>("abc"))
1458    ///     .get_result::<serde_json::Value>(connection)?;
1459    /// assert_eq!(json!(["abc"]), result);
1460    ///
1461    /// let result = diesel::select(jsonb_array_2::<Text, Double, _, _>("abc", 3.1415))
1462    ///     .get_result::<serde_json::Value>(connection)?;
1463    /// assert_eq!(json!(["abc", 3.1415]), result);
1464    /// #
1465    /// # Ok(())
1466    /// # }
1467    /// ```
1468    #[cfg(feature = "sqlite")]
1469    #[variadic(1)]
1470    fn jsonb_array<V: NotBlob>(value: V) -> Jsonb;
1471
1472    /// The `json_remove(X,P,...)` SQL function takes a single JSON value as its first argument followed by
1473    /// zero or more path arguments. The `json_remove(X,P,...)` function returns a copy of the X parameter
1474    /// with all the elements identified by path arguments removed. Paths that select elements not found in X
1475    /// are silently ignored.
1476    ///
1477    /// Removals occurs sequentially from left to right. Changes caused by prior removals can affect the path
1478    /// search for subsequent arguments.
1479    ///
1480    /// If the `json_remove(X)` function is called with no path arguments, then it returns the input X
1481    /// reformatted, with excess whitespace removed.
1482    ///
1483    /// The `json_remove()` function throws an error if any of the path arguments is not a well-formed path.
1484    ///
1485    /// This function requires at least SQLite 3.38 or newer
1486    ///
1487    /// # Examples
1488    ///
1489    /// ```rust
1490    /// # include!("../../doctest_setup.rs");
1491    /// #
1492    /// # fn main() {
1493    /// #     #[cfg(feature = "serde_json")]
1494    /// #     run_test().unwrap();
1495    /// # }
1496    /// #
1497    /// # #[cfg(feature = "serde_json")]
1498    /// # fn run_test() -> QueryResult<()> {
1499    /// #     use diesel::dsl::*;
1500    /// #     use diesel::sql_types::{Json, Text};
1501    /// #     use serde_json::json;
1502    /// #
1503    /// #     let connection = &mut establish_connection();
1504    /// #     assert_version!(connection, 3, 38, 0);
1505    /// #
1506    /// let json = json!(['a', 'b', 'c', 'd']);
1507    /// let result = diesel::select(json_remove_0::<Json, _>(json))
1508    ///     .get_result::<Option<serde_json::Value>>(connection)?;
1509    /// assert_eq!(Some(json!(['a', 'b', 'c', 'd'])), result);
1510    ///
1511    /// // Values are removed sequentially from left to right.
1512    /// let json = json!(['a', 'b', 'c', 'd']);
1513    /// let result = diesel::select(json_remove_2::<Json, _, _, _>(json, "$[0]", "$[2]"))
1514    ///     .get_result::<Option<serde_json::Value>>(connection)?;
1515    /// assert_eq!(Some(json!(['b', 'c'])), result);
1516    ///
1517    /// let json = json!({"a": 10, "b": 20});
1518    /// let result = diesel::select(json_remove_1::<Json, _, _>(json, "$.a"))
1519    ///     .get_result::<Option<serde_json::Value>>(connection)?;
1520    /// assert_eq!(Some(json!({"b": 20})), result);
1521    ///
1522    /// // Paths that select not existing elements are silently ignored.
1523    /// let json = json!({"a": 10, "b": 20});
1524    /// let result = diesel::select(json_remove_1::<Json, _, _>(json, "$.c"))
1525    ///     .get_result::<Option<serde_json::Value>>(connection)?;
1526    /// assert_eq!(Some(json!({"a": 10, "b": 20})), result);
1527    ///
1528    /// let json = json!({"a": 10, "b": 20});
1529    /// let result = diesel::select(json_remove_1::<Json, _, _>(json, "$"))
1530    ///     .get_result::<Option<serde_json::Value>>(connection)?;
1531    /// assert_eq!(None, result);
1532    ///
1533    /// #
1534    /// # Ok(())
1535    /// # }
1536    /// ```
1537    #[cfg(feature = "sqlite")]
1538    #[variadic(1)]
1539    fn json_remove<J: JsonOrNullableJsonOrJsonbOrNullableJsonb + SingleValue>(
1540        json: J,
1541        path: Text,
1542    ) -> Nullable<Json>;
1543
1544    /// The `jsonb_remove(X,P,...)` SQL function takes a single JSON value as its first argument followed by
1545    /// zero or more path arguments. The `jsonb_remove(X,P,...)` function returns a copy of the X parameter
1546    /// with all the elements identified by path arguments removed. Paths that select elements not found in X
1547    /// are silently ignored.
1548    ///
1549    /// Removals occurs sequentially from left to right. Changes caused by prior removals can affect the path
1550    /// search for subsequent arguments.
1551    ///
1552    /// If the `jsonb_remove(X)` function is called with no path arguments, then it returns the input X
1553    /// reformatted, with excess whitespace removed.
1554    ///
1555    /// The `jsonb_remove()` function throws an error if any of the path arguments is not a well-formed path.
1556    ///
1557    /// This function returns value in a binary JSONB format.
1558    ///
1559    /// This function requires at least SQLite 3.38 or newer
1560    ///
1561    /// # Examples
1562    ///
1563    /// ```rust
1564    /// # include!("../../doctest_setup.rs");
1565    /// #
1566    /// # fn main() {
1567    /// #     #[cfg(feature = "serde_json")]
1568    /// #     run_test().unwrap();
1569    /// # }
1570    /// #
1571    /// # #[cfg(feature = "serde_json")]
1572    /// # fn run_test() -> QueryResult<()> {
1573    /// #     use diesel::dsl::*;
1574    /// #     use diesel::sql_types::{Jsonb, Text};
1575    /// #     use serde_json::json;
1576    /// #
1577    /// #     let connection = &mut establish_connection();
1578    /// #     assert_version!(connection, 3, 38, 0);
1579    /// #
1580    /// let json = json!(['a', 'b', 'c', 'd']);
1581    /// let result = diesel::select(jsonb_remove_0::<Jsonb, _>(json))
1582    ///     .get_result::<Option<serde_json::Value>>(connection)?;
1583    /// assert_eq!(Some(json!(['a', 'b', 'c', 'd'])), result);
1584    ///
1585    /// // Values are removed sequentially from left to right.
1586    /// let json = json!(['a', 'b', 'c', 'd']);
1587    /// let result = diesel::select(jsonb_remove_2::<Jsonb, _, _, _>(json, "$[0]", "$[2]"))
1588    ///     .get_result::<Option<serde_json::Value>>(connection)?;
1589    /// assert_eq!(Some(json!(['b', 'c'])), result);
1590    ///
1591    /// let json = json!({"a": 10, "b": 20});
1592    /// let result = diesel::select(jsonb_remove_1::<Jsonb, _, _>(json, "$.a"))
1593    ///     .get_result::<Option<serde_json::Value>>(connection)?;
1594    /// assert_eq!(Some(json!({"b": 20})), result);
1595    ///
1596    /// // Paths that select not existing elements are silently ignored.
1597    /// let json = json!({"a": 10, "b": 20});
1598    /// let result = diesel::select(jsonb_remove_1::<Jsonb, _, _>(json, "$.c"))
1599    ///     .get_result::<Option<serde_json::Value>>(connection)?;
1600    /// assert_eq!(Some(json!({"a": 10, "b": 20})), result);
1601    ///
1602    /// let json = json!({"a": 10, "b": 20});
1603    /// let result = diesel::select(jsonb_remove_1::<Jsonb, _, _>(json, "$"))
1604    ///     .get_result::<Option<serde_json::Value>>(connection)?;
1605    /// assert_eq!(None, result);
1606    ///
1607    /// #
1608    /// # Ok(())
1609    /// # }
1610    /// ```
1611    #[cfg(feature = "sqlite")]
1612    #[variadic(1)]
1613    fn jsonb_remove<J: JsonOrNullableJsonOrJsonbOrNullableJsonb + SingleValue>(
1614        json: J,
1615        path: Text,
1616    ) -> Nullable<Jsonb>;
1617
1618    /// Applies an RFC 7396 MergePatch `patch` to the input JSON `target` and
1619    /// returns the patched JSON value.
1620    ///
1621    /// MergePatch can add, modify, or delete elements of a JSON object. Arrays are
1622    /// treated as atomic values: they can only be inserted, replaced, or deleted as a
1623    /// whole, not modified element-wise.
1624    ///
1625    /// # Examples
1626    ///
1627    /// ```rust
1628    /// # include!("../../doctest_setup.rs");
1629    /// #
1630    /// # fn main() {
1631    /// #     #[cfg(feature = "serde_json")]
1632    /// #     run_test().unwrap();
1633    /// # }
1634    /// #
1635    /// # #[cfg(feature = "serde_json")]
1636    /// # fn run_test() -> QueryResult<()> {
1637    /// #     use diesel::dsl::json_patch;
1638    /// #     use serde_json::{json, Value};
1639    /// #     use diesel::sql_types::{Json, Nullable};
1640    /// #     let connection = &mut establish_connection();
1641    ///
1642    /// let result = diesel::select(json_patch::<Json, Json, _, _>(
1643    ///     json!( {"a":1,"b":2} ),
1644    ///     json!( {"c":3,"d":4} ),
1645    /// ))
1646    /// .get_result::<Value>(connection)?;
1647    /// assert_eq!(json!({"a":1,"b":2,"c":3,"d":4}), result);
1648    ///
1649    /// let result = diesel::select(json_patch::<Json, Json, _, _>(
1650    ///     json!( {"a":[1,2],"b":2} ),
1651    ///     json!( {"a":9} ),
1652    /// ))
1653    /// .get_result::<Value>(connection)?;
1654    /// assert_eq!(json!({"a":9,"b":2}), result);
1655    ///
1656    /// let result = diesel::select(json_patch::<Json, Json, _, _>(
1657    ///     json!( {"a":[1,2],"b":2} ),
1658    ///     json!( {"a":null} ),
1659    /// ))
1660    /// .get_result::<Value>(connection)?;
1661    /// assert_eq!(json!({"b":2}), result);
1662    ///
1663    /// let result = diesel::select(json_patch::<Json, Json, _, _>(
1664    ///     json!( {"a":1,"b":2} ),
1665    ///     json!( {"a":9,"b":null,"c":8} ),
1666    /// ))
1667    /// .get_result::<Value>(connection)?;
1668    /// assert_eq!(json!({"a":9,"c":8}), result);
1669    ///
1670    /// let result = diesel::select(json_patch::<Json, Json, _, _>(
1671    ///     json!( {"a":{"x":1,"y":2},"b":3} ),
1672    ///     json!( {"a":{"y":9},"c":8} ),
1673    /// ))
1674    /// .get_result::<Value>(connection)?;
1675    /// assert_eq!(
1676    ///     json!({"a":{"x":1,"y":9},"b":3,"c":8}),
1677    ///     result
1678    /// );
1679    ///
1680    /// // Nullable input yields nullable output
1681    /// let result = diesel::select(json_patch::<Nullable<Json>, Json, _, _>(
1682    ///     None::<Value>,
1683    ///     json!({}),
1684    /// ))
1685    /// .get_result::<Option<Value>>(connection)?;
1686    /// assert!(result.is_none());
1687    ///
1688    /// #     Ok(())
1689    /// # }
1690    /// ```
1691    #[cfg(feature = "sqlite")]
1692    fn json_patch<
1693        T: JsonOrNullableJsonOrJsonbOrNullableJsonb + SingleValue,
1694        P: JsonOrNullableJsonOrJsonbOrNullableJsonb + SingleValue + CombinedNullableValue<T, Json>,
1695    >(
1696        target: T,
1697        patch: P,
1698    ) -> P::Out;
1699
1700    /// Applies an RFC 7396 MergePatch `patch` to the input JSON `target` and
1701    /// returns the patched JSON value in SQLite's binary JSONB format.
1702    ///
1703    /// See [`json_patch`](json_patch()) for details about the MergePatch semantics.
1704    ///
1705    /// # Examples
1706    ///
1707    /// ```rust
1708    /// # include!("../../doctest_setup.rs");
1709    /// #
1710    /// # fn main() {
1711    /// #     #[cfg(feature = "serde_json")]
1712    /// #     run_test().unwrap();
1713    /// # }
1714    /// #
1715    /// # #[cfg(feature = "serde_json")]
1716    /// # fn run_test() -> QueryResult<()> {
1717    /// #     use diesel::dsl::jsonb_patch;
1718    /// #     use serde_json::{json, Value};
1719    /// #     use diesel::sql_types::{Jsonb, Nullable};
1720    /// #     let connection = &mut establish_connection();
1721    /// #     assert_version!(connection, 3, 45, 0);
1722    ///
1723    /// let result = diesel::select(jsonb_patch::<Jsonb, Jsonb, _, _>(
1724    ///     json!( {"a":1,"b":2} ),
1725    ///     json!( {"c":3,"d":4} ),
1726    /// ))
1727    /// .get_result::<Value>(connection)?;
1728    /// assert_eq!(json!({"a":1,"b":2,"c":3,"d":4}), result);
1729    ///
1730    /// // Nullable input yields nullable output
1731    /// let result = diesel::select(jsonb_patch::<Nullable<Jsonb>, Jsonb, _, _>(
1732    ///     None::<Value>,
1733    ///     json!({}),
1734    /// ))
1735    /// .get_result::<Option<Value>>(connection)?;
1736    /// assert!(result.is_none());
1737    ///
1738    /// #     Ok(())
1739    /// # }
1740    /// ```
1741    #[cfg(feature = "sqlite")]
1742    fn jsonb_patch<
1743        T: JsonOrNullableJsonOrJsonbOrNullableJsonb + SingleValue,
1744        P: JsonOrNullableJsonOrJsonbOrNullableJsonb + SingleValue + CombinedNullableValue<T, Jsonb>,
1745    >(
1746        target: T,
1747        patch: P,
1748    ) -> P::Out;
1749}
1750
1751pub(super) mod return_type_helpers_reexported {
1752    #[allow(unused_imports)]
1753    #[doc(inline)]
1754    pub use super::return_type_helpers::*;
1755}