pub fn json_array_1<V1: NotBlob, value_1>(
value_1: value_1,
) -> json_array_1<V1, value_1>where
value_1: AsExpression<V1>,
sqlite
only.Expand description
The json_array()
SQL function accepts zero or more arguments and returns a well-formed JSON array
that is composed from those arguments. Note that arguments of type BLOB will not be accepted by this
function.
An argument with SQL type TEXT is normally converted into a quoted JSON string. However, if the
argument is the output from another json function, then it is stored as JSON. This allows calls to
json_array()
and json_object()
to be nested. The json()
function can also be used to force
strings to be recognized as JSON.
This function requires at least SQLite 3.38 or newer
§Examples
let result = diesel::select(json_array_0()).get_result::<serde_json::Value>(connection)?;
assert_eq!(json!([]), result);
let result = diesel::select(json_array_1::<Text, _>("abc"))
.get_result::<serde_json::Value>(connection)?;
assert_eq!(json!(["abc"]), result);
let result = diesel::select(json_array_2::<Text, Double, _, _>("abc", 3.1415))
.get_result::<serde_json::Value>(connection)?;
assert_eq!(json!(["abc", 3.1415]), result);
§Variadic functions
This function is variadic in SQL, so there’s a family of functions on a diesel side:
json_array_0
, json_array_1
, … json_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.