Repository: diesel-rs/diesel
File: diesel/src/sqlite/expression/functions.rs (Rust)

Code before:
    /// #
    /// let result = diesel::select(json_object_0()).get_result::<serde_json::Value>(connection)?;
    /// assert_eq!(json!({}), result);
    ///
    /// let result = diesel::select(json_object_1::<Text, Integer, _, _>("a", 2))
    ///     .get_result::<serde_json::Value>(connection)?;
    /// assert_eq!(json!({"a": 2}), result);
    ///
    /// let result = diesel::select(
    ///     json_object_2::<Text, Integer, Text, Text, _, _, _, _>("a", 2, "c", "{e:5}")
    /// )
    /// .get_result::<serde_json::Value>(connection)?;
    /// assert_eq!(json!({"a": 2, "c": "{e:5}"}), result);
    ///
    /// let result = diesel::select(
    ///     json_object_2::<Text, Integer, Text, Json, _, _, _, _>("a", 2, "c", json_object_1::<Text, Integer, _, _>("e", 5))
    /// )
    /// .get_result::<serde_json::Value>(connection)?;
    /// assert_eq!(json!({"a": 2, "c": {"e": 5}}), result);
    /// #
    /// # Ok(())
    /// # }
    /// ```
    #[cfg(feature = "sqlite")]
    #[variadic(2)]
    fn json_object<K: NotBlob, V: NotBlob>(key: K, value: V) -> Json;

    /// The `jsonb_object()` SQL function works just like the [`json_object()`](json_object_1())
    /// function except that the generated object is returned in SQLite's private binary JSONB
    /// format rather than in the standard RFC 8259 text format.
    ///
    /// This function requires at least SQLite 3.38 or newer
    ///
    /// # Examples
    ///
    /// ```rust
    /// # include!("../../doctest_setup.rs");
    /// #
    /// # fn main() {
    /// #     #[cfg(feature = "serde_json")]
    /// #     run_test().unwrap();
    /// # }
    /// #
    /// # #[cfg(feature = "serde_json")]
    /// # fn run_test() -> QueryResult<()> {
    /// #     use diesel::dsl::*;
    /// #     use diesel::sql_types::{Text, Integer};
    /// #     use serde_json::json;
    /// #
    /// #     let connection = &mut establish_connection();
    /// #     assert_version!(connection, 3, 38, 0);

Review comment (suggestion):
We need to restrict the keys to be not a null value as SQLite doesn't accept a null value there. We should be able to do this via `K: NotBlob<IsNull = is_nullable::NotNull>`. This also applies to `jsonb_object`.

Code after:
    /// #
    /// let result = diesel::select(json_object_0()).get_result::<serde_json::Value>(connection)?;
    /// assert_eq!(json!({}), result);
    ///
    /// let result = diesel::select(json_object_1::<Text, Integer, _, _>("a", 2))
    ///     .get_result::<serde_json::Value>(connection)?;
    /// assert_eq!(json!({"a": 2}), result);
    ///
    /// let result = diesel::select(
    ///     json_object_2::<Text, Integer, Text, Text, _, _, _, _>("a", 2, "c", "{e:5}")
    /// )
    /// .get_result::<serde_json::Value>(connection)?;
    /// assert_eq!(json!({"a": 2, "c": "{e:5}"}), result);
    ///
    /// let result = diesel::select(
    ///     json_object_2::<Text, Integer, Text, Json, _, _, _, _>("a", 2, "c", json_object_1::<Text, Integer, _, _>("e", 5))
    /// )
    /// .get_result::<serde_json::Value>(connection)?;
    /// assert_eq!(json!({"a": 2, "c": {"e": 5}}), result);
    /// #
    /// # Ok(())
    /// # }
    /// ```
    #[cfg(feature = "sqlite")]
    #[variadic(2)]
    fn json_object<K: NotBlob<IsNull = is_nullable::NotNull>, V: NotBlob>(key: K, value: V)
        -> Json;

    /// The `jsonb_object()` SQL function works just like the [`json_object()`](json_object_1())
    /// function except that the generated object is returned in SQLite's private binary JSONB
    /// format rather than in the standard RFC 8259 text format.
    ///
    /// This function requires at least SQLite 3.38 or newer
    ///
    /// # Examples
    ///
    /// ```rust
    /// # include!("../../doctest_setup.rs");
    /// #
    /// # fn main() {
    /// #     #[cfg(feature = "serde_json")]
    /// #     run_test().unwrap();
    /// # }
    /// #
    /// # #[cfg(feature = "serde_json")]
    /// # fn run_test() -> QueryResult<()> {
    /// #     use diesel::dsl::*;
    /// #     use diesel::sql_types::{Text, Integer};
    /// #     use serde_json::json;
    /// #
    /// #     let connection = &mut establish_connection();