json_group_array

Function json_group_array 

Source
pub fn json_group_array<E: SqlType + SingleValue, elements>(
    elements: elements,
) -> json_group_array<E, elements>
where elements: AsExpression<E>,
Available on crate feature sqlite only.
Expand description

The json_group_array(X) function is an aggregate SQL function that returns a JSON array comprised of all X values in the aggregation.

§Aggregate Function Expression

This function can be used as aggregate expression. See AggregateExpressionMethods for details.

§Examples

§Normal function usage

let result = animals
    .select(json_group_array(species))
    .get_result::<serde_json::Value>(connection)?;
assert_eq!(result, json!(["dog", "spider"]));

let result = animals
    .select(json_group_array(legs))
    .get_result::<serde_json::Value>(connection)?;
assert_eq!(result, json!([4, 8]));

let result = animals
    .select(json_group_array(name))
    .get_result::<serde_json::Value>(connection)?;
assert_eq!(result, json!(["Jack", null]));

§Aggregate function expression

let result = animals
    .select(json_group_array(species).aggregate_filter(legs.lt(8)))
    .get_result::<serde_json::Value>(connection)?;
assert_eq!(result, json!(["dog"]));

§See also