pub trait AggregateExpressionMethods: Sized {
// Provided methods
fn aggregate_distinct(self) -> AggregateDistinct<Self>
where Self: DistinctDsl { ... }
fn aggregate_all(self) -> AggregateAll<Self>
where Self: AllDsl { ... }
fn aggregate_filter<P>(self, f: P) -> AggregateFilter<Self, P>
where P: AsExpression<Bool>,
Self: FilterDsl<P::Expression> { ... }
fn aggregate_order<O>(self, o: O) -> AggregateOrder<Self, O>
where Self: OrderAggregateDsl<O> { ... }
}
Expand description
Expression methods to build aggregate function expressions
Provided Methods§
Sourcefn aggregate_distinct(self) -> AggregateDistinct<Self>where
Self: DistinctDsl,
fn aggregate_distinct(self) -> AggregateDistinct<Self>where
Self: DistinctDsl,
DISTINCT
modifier for aggregate functions
This modifies the aggregate function call to only include distinct items
§Example
let without_distinct = posts
.select(dsl::count(user_id))
.get_result::<i64>(connection)?;
let with_distinct = posts
.select(dsl::count(user_id).aggregate_distinct())
.get_result::<i64>(connection)?;
assert_eq!(3, without_distinct);
assert_eq!(2, with_distinct);
Sourcefn aggregate_all(self) -> AggregateAll<Self>where
Self: AllDsl,
fn aggregate_all(self) -> AggregateAll<Self>where
Self: AllDsl,
ALL
modifier for aggregate functions
This modifies the aggregate function call to include all items. This is the default behaviour.
§Example
let without_all = posts
.select(dsl::count(user_id))
.get_result::<i64>(connection)?;
let with_all = posts
.select(dsl::count(user_id).aggregate_all())
.get_result::<i64>(connection)?;
assert_eq!(3, without_all);
assert_eq!(3, with_all);
Sourcefn aggregate_filter<P>(self, f: P) -> AggregateFilter<Self, P>
fn aggregate_filter<P>(self, f: P) -> AggregateFilter<Self, P>
Add an aggregate function filter
This function modifies an aggregate function call to use only items matching the provided filter
§Example
let without_filter = posts
.select(dsl::count(user_id))
.get_result::<i64>(connection)?;
let with_filter = posts
.select(dsl::count(user_id).aggregate_filter(title.like("%first post%")))
.get_result::<i64>(connection)?;
assert_eq!(3, without_filter);
assert_eq!(2, with_filter);
Sourcefn aggregate_order<O>(self, o: O) -> AggregateOrder<Self, O>where
Self: OrderAggregateDsl<O>,
fn aggregate_order<O>(self, o: O) -> AggregateOrder<Self, O>where
Self: OrderAggregateDsl<O>,
Add an aggregate function order
This function orders the items passed into an aggregate function
For sqlite this is only supported starting with SQLite 3.44
§Example
// This example is not meaningful yet,
// modify it as soon as we support more
// meaningful functions here
let res = posts
.select(dsl::count(user_id).aggregate_order(title))
.get_result::<i64>(connection)?;
assert_eq!(3, res);
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.