pub fn json_array_length<J: JsonOrNullableJsonOrJsonbOrNullableJsonb + MaybeNullableValue<Integer>, j>(
j: j,
) -> json_array_length<J, j>where
j: AsExpression<J>,
Available on crate feature
sqlite
only.Expand description
The json_array_length(X) function returns the number of elements in the JSON array X, or 0 if X is some kind of JSON value other than an array. Errors are thrown if either X is not well-formed JSON or if P is not a well-formed path.
This function requires at least SQLite 3.46 or newer
ยงExample
let result = diesel::select(json_array_length::<Json, _>(json!([1,2,3,4])))
.get_result::<i32>(connection)?;
assert_eq!(4, result);
let result = diesel::select(json_array_length::<Json, _>(json!({"one":[1,2,3]})))
.get_result::<i32>(connection)?;
assert_eq!(0, result);
let result = diesel::select(json_array_length::<Nullable<Json>, _>(None::<Value>))
.get_result::<Option<i32>>(connection)?;
assert_eq!(None, result);
let result = diesel::select(json_array_length::<Jsonb, _>(json!([1,2,3,4])))
.get_result::<i32>(connection)?;
assert_eq!(4, result);
let result = diesel::select(json_array_length::<Jsonb, _>(json!({"one":[1,2,3]})))
.get_result::<i32>(connection)?;
assert_eq!(0, result);
let result = diesel::select(json_array_length::<Nullable<Jsonb>, _>(None::<Value>))
.get_result::<Option<i32>>(connection)?;
assert_eq!(None, result);