pub fn jsonb_insert_0<J: JsonOrNullableJsonOrJsonbOrNullableJsonb + MaybeNullableValue<Jsonb> + SingleValue, json>(
json: json,
) -> jsonb_insert_0<J, json>where
json: AsExpression<J>,__sqlite-shared only.Expand description
The jsonb_insert(X,P,V,...) SQL function works just like the json_insert()
function except that the result is returned in SQLite’s private binary JSONB format rather than
in the standard RFC 8259 text format.
§Variadic functions
This function is variadic in SQL, so there’s a family of functions on a diesel side:
jsonb_insert_0, jsonb_insert_1, … jsonb_insert_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.
This function requires at least SQLite 3.38 or newer
§Examples
let json = json!({"a": 1, "c": 3});
let result = diesel::select(jsonb_insert_1::<Jsonb, Integer, _, _, _>(json, "$.b", 2))
.get_result::<serde_json::Value>(connection)?;
assert_eq!(json!({"a": 1, "b": 2, "c": 3}), result);
// A path that already exists is left unchanged.
let json = json!({"a": 1});
let result = diesel::select(jsonb_insert_1::<Jsonb, Integer, _, _, _>(json, "$.a", 99))
.get_result::<serde_json::Value>(connection)?;
assert_eq!(json!({"a": 1}), result);
// A path ending in "[#]" appends to an array.
let json = json!(['a', 'b', 'c']);
let result = diesel::select(jsonb_insert_1::<Jsonb, Text, _, _, _>(json, "$[#]", "d"))
.get_result::<serde_json::Value>(connection)?;
assert_eq!(json!(['a', 'b', 'c', 'd']), result);
let json = json!({"a": 1});
let result = diesel::select(
jsonb_insert_2::<Jsonb, Integer, Integer, _, _, _, _, _>(json, "$.b", 2, "$.c", 3),
)
.get_result::<serde_json::Value>(connection)?;
assert_eq!(json!({"a": 1, "b": 2, "c": 3}), result);
let json = json!({"a": 1});
let result = diesel::select(jsonb_insert_0::<Jsonb, _>(json))
.get_result::<serde_json::Value>(connection)?;
assert_eq!(json!({"a": 1}), result);
let result = diesel::select(jsonb_insert_1::<Nullable<Jsonb>, Integer, _, _, _>(None::<serde_json::Value>, "$.b", 1))
.get_result::<Option<serde_json::Value>>(connection)?;
assert_eq!(result, None);