pub fn jsonb_replace_0<J: JsonOrNullableJsonOrJsonbOrNullableJsonb + MaybeNullableValue<Jsonb> + SingleValue, json>(
json: json,
) -> jsonb_replace_0<J, json>where
json: AsExpression<J>,__sqlite-shared only.Expand description
The jsonb_replace(X,P,V,...) SQL function works just like the json_replace()
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_replace_0, jsonb_replace_1, … jsonb_replace_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, "b": 2});
let result = diesel::select(jsonb_replace_1::<Jsonb, Integer, _, _, _>(json, "$.a", 99))
.get_result::<serde_json::Value>(connection)?;
assert_eq!(json!({"a": 99, "b": 2}), result);
// A path that does not exist is silently ignored.
let json = json!({"a": 1});
let result = diesel::select(jsonb_replace_1::<Jsonb, Integer, _, _, _>(json, "$.b", 2))
.get_result::<serde_json::Value>(connection)?;
assert_eq!(json!({"a": 1}), result);
let json = json!({"a": 1});
let result = diesel::select(jsonb_replace_0::<Jsonb, _>(json))
.get_result::<serde_json::Value>(connection)?;
assert_eq!(json!({"a": 1}), result);
let result = diesel::select(jsonb_replace_1::<Nullable<Jsonb>, Integer, _, _, _>(None::<serde_json::Value>, "$.a", 1))
.get_result::<Option<serde_json::Value>>(connection)?;
assert_eq!(result, None);