pub fn jsonb_array_1<V1: NotBlob, value_1>(
value_1: value_1,
) -> jsonb_array_1<V1, value_1>where
value_1: AsExpression<V1>,
sqlite
only.Expand description
The jsonb_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
jsonb_array()
and jsonb_object()
to be nested. The json()
function can also be used to force
strings to be recognized as JSON.
This function works just like the json_array()
function except that it returns the
constructed JSON array in the SQLite’s private 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_array_0()).get_result::<serde_json::Value>(connection)?;
assert_eq!(json!([]), result);
let result = diesel::select(jsonb_array_1::<Text, _>("abc"))
.get_result::<serde_json::Value>(connection)?;
assert_eq!(json!(["abc"]), result);
let result = diesel::select(jsonb_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:
jsonb_array_0
, jsonb_array_1
, … jsonb_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.