pub struct WindowSpec<'a, V: SQLParam, S = ()> { /* private fields */ }Expand description
The contents of an OVER (...) clause; start one with window.
S records the tables that PARTITION BY and ORDER BY read, for the
query’s scope check.
§Examples
let spec = window()
.partition_by([users.name])
.order_by(asc(users.created_at))
.rows_between(FrameBound::UnboundedPreceding, FrameBound::CurrentRow);
let total = sum(users.score).over(spec);
assert_eq!(
total.sql(),
r#"SUM ("users"."score") OVER (PARTITION BY "users"."name" ORDER BY "users"."created_at" ASC ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW)"#
);Implementations§
Source§impl<'a, V: SQLParam + 'a, S> WindowSpec<'a, V, S>
impl<'a, V: SQLParam + 'a, S> WindowSpec<'a, V, S>
Sourcepub fn partition_by<I>(
self,
exprs: I,
) -> WindowSpec<'a, V, (S, ScopeOnly<<I::Item as ExprSources>::Sources>)>
pub fn partition_by<I>( self, exprs: I, ) -> WindowSpec<'a, V, (S, ScopeOnly<<I::Item as ExprSources>::Sources>)>
Sets PARTITION BY; the window restarts for each distinct value.
Takes an array or other iterator of expressions of one Rust type.
Sourcepub fn order_by<T: ToSQL<'a, V> + ExprSources>(
self,
exprs: T,
) -> WindowSpec<'a, V, (S, ScopeOnly<T::Sources>)>
pub fn order_by<T: ToSQL<'a, V> + ExprSources>( self, exprs: T, ) -> WindowSpec<'a, V, (S, ScopeOnly<T::Sources>)>
Sets ORDER BY inside the window.
Takes one ordering term such as asc(col), or a tuple or
array of terms.
Sourcepub fn rows_between(self, start: FrameBound, end: FrameBound) -> Self
pub fn rows_between(self, start: FrameBound, end: FrameBound) -> Self
Sets a ROWS BETWEEN start AND end frame, counted in rows.
Sourcepub fn range_between(self, start: FrameBound, end: FrameBound) -> Self
pub fn range_between(self, start: FrameBound, end: FrameBound) -> Self
Sets a RANGE BETWEEN start AND end frame, measured in ORDER BY values.
Trait Implementations§
Auto Trait Implementations§
impl<'a, V, S> Freeze for WindowSpec<'a, V, S>
impl<'a, V, S> RefUnwindSafe for WindowSpec<'a, V, S>
impl<'a, V, S> Send for WindowSpec<'a, V, S>
impl<'a, V, S> Sync for WindowSpec<'a, V, S>
impl<'a, V, S> Unpin for WindowSpec<'a, V, S>
impl<'a, V, S> UnsafeUnpin for WindowSpec<'a, V, S>
impl<'a, V, S> UnwindSafe for WindowSpec<'a, V, S>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more