jsonb_object_1

Function jsonb_object_1 

Source
pub fn jsonb_object_1<K1: NotBlob<IsNull = NotNull>, V1: NotBlob, key_1, value_1>(
    key_1: key_1,
    value_1: value_1,
) -> jsonb_object_1<K1, V1, key_1, value_1>
where key_1: AsExpression<K1>, value_1: AsExpression<V1>,
Available on crate feature sqlite only.
Expand description

The jsonb_object() SQL function works just like the json_object() 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

let result = diesel::select(jsonb_object_0()).get_result::<serde_json::Value>(connection)?;
assert_eq!(json!({}), result);

let result = diesel::select(jsonb_object_1::<Text, Integer, _, _>("a", 2))
    .get_result::<serde_json::Value>(connection)?;
assert_eq!(json!({"a": 2}), result);

let result = diesel::select(
    jsonb_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);

§Variadic functions

This function is variadic in SQL, so there’s a family of functions on a diesel side:

jsonb_object_0, jsonb_object_1, … jsonb_object_n

Here, the postfix number indicates repetitions of variadic arguments. To use this function, the appropriate version with the correct argument count must be selected.

§Controlling the generation of variadic function variants

By default, only variants with 0, 1, and 2 repetitions of variadic arguments are generated. To generate more variants, set the DIESEL_VARIADIC_FUNCTION_ARGS environment variable to the desired number of variants.

For a greater convenience this environment variable can also be set in a .cargo/config.toml file as described in the cargo documentation.