pub fn json_build_array_2<V1: SingleValue, V2: SingleValue, value_1, value_2>(
value_1: value_1,
value_2: value_2,
) -> json_build_array_2<V1, V2, value_1, value_2>where
value_1: AsExpression<V1>,
value_2: AsExpression<V2>,postgres_backend only.Expand description
Builds a possibly-heterogeneously-typed JSON array out of a variadic argument list. Each argument is converted as per to_json.
§Example
let result = diesel::select(json_build_array_0()).get_result::<serde_json::Value>(connection)?;
assert_eq!(json!([]), result);
let result = diesel::select(json_build_array_1::<Text, _>("abc"))
.get_result::<serde_json::Value>(connection)?;
assert_eq!(json!(["abc"]), result);
let result = diesel::select(json_build_array_2::<Text, Double, _, _>("abc", 3.1415))
.get_result::<serde_json::Value>(connection)?;
assert_eq!(json!(["abc", 3.1415]), result);
let result = diesel::select(json_build_array_1::<Record<(Text, Double)>, _>(sql::<Record<(Text, Double)>>("ROW('abc',3.1415)")))
.get_result::<serde_json::Value>(connection)?;
assert_eq!(json!([
{
"f1":"abc",
"f2":3.1415
}
]), result);
let result = diesel::select(json_build_array_1::<Array<Integer>, _>(vec![1, 2, 3]))
.get_result::<serde_json::Value>(connection)?;
assert_eq!(json!([ [1, 2, 3] ]), result);
let result = diesel::select(json_build_array_2::<Nullable<Text>, Double, _, _>(None::<String>, 3.1415))
.get_result::<serde_json::Value>(connection)?;
assert_eq!(json!([None::<String>, 3.1415]), result);
let result = diesel::select(json_build_array_1::<Record<(Nullable<Text>, Double)>, _>(sql::<Record<(Nullable<Text>, Double)>>("ROW(null,3.1415)")))
.get_result::<serde_json::Value>(connection)?;
assert_eq!(json!([
{
"f1":None::<String>,
"f2":3.1415
}
]), result);
§Variadic functions
This function is variadic in SQL, so there’s a family of functions on a diesel side:
json_build_array_0, json_build_array_1, … json_build_array_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.