WindowExpressionMethods

Trait WindowExpressionMethods 

Source
pub trait WindowExpressionMethods: Sized {
    // Provided methods
    fn over(self) -> Over<Self>
       where Self: OverDsl { ... }
    fn window_filter<P>(self, f: P) -> WindowFilter<Self, P>
       where P: AsExpression<Bool>,
             Self: FilterDsl<P::Expression> { ... }
    fn partition_by<E>(self, expr: E) -> PartitionBy<Self, E>
       where Self: PartitionByDsl<E> { ... }
    fn window_order<E>(self, expr: E) -> WindowOrder<Self, E>
       where Self: OrderWindowDsl<E> { ... }
    fn frame_by<E>(self, expr: E) -> FrameBy<Self, E>
       where Self: FrameDsl<E> { ... }
}
Expand description

Methods to construct a window function call

Provided Methods§

Source

fn over(self) -> Over<Self>
where Self: OverDsl,

Turn a function call into a window function call

This function turns a ordinary SQL function call into a window function call by adding an empty OVER () clause

§Example
let res = posts
    .select(dsl::count(user_id).over())
    .load::<i64>(connection)?;
assert_eq!(vec![3, 3, 3], res);
Source

fn window_filter<P>(self, f: P) -> WindowFilter<Self, P>
where P: AsExpression<Bool>, Self: FilterDsl<P::Expression>,

Add a filter to the current window function

§Example
let res = posts
    .select(dsl::count(user_id).window_filter(user_id.eq(1)))
    .load::<i64>(connection)?;
assert_eq!(vec![2], res);
Source

fn partition_by<E>(self, expr: E) -> PartitionBy<Self, E>
where Self: PartitionByDsl<E>,

Add a partition clause to the current window function

This function adds a PARTITION BY clause to your window function call

§Example
let res = posts
    .select(dsl::count(user_id).partition_by(user_id))
    .load::<i64>(connection)?;
assert_eq!(vec![2, 2, 1], res);
Source

fn window_order<E>(self, expr: E) -> WindowOrder<Self, E>
where Self: OrderWindowDsl<E>,

Add a order clause to the current window function

Add a ORDER BY clause to your window function call

§Example
let res = posts
    .select(dsl::first_value(user_id).window_order(title))
    .load::<i32>(connection)?;
assert_eq!(vec![1, 1, 1], res);
Source

fn frame_by<E>(self, expr: E) -> FrameBy<Self, E>
where Self: FrameDsl<E>,

Add a frame clause to the current window function

This function adds a frame clause to your window function call. Accepts the following items:

§Example
let res = posts
    .select(
        dsl::count(user_id).frame_by(dsl::frame::Rows.frame_start_with(dsl::frame::CurrentRow)),
    )
    .load::<i64>(connection)?;
assert_eq!(vec![1, 1, 1], 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.

Implementors§