pub struct Window<E: Entity> { /* private fields */ }
Expand description
SQL window functions.
§Examples
use crate::model::{User, UserColumn::*};
use zino_orm::{QueryBuilder, Schema, Window};
let rank_window = Window::rank(CurrentLoginIp).order_desc(LoginCount);
let query = QueryBuilder::<User>::new()
.fields([Id, Name, CurrentLoginIp, LoginCount])
.window(rank_window, Some("login_count_rank"))
.and_not_in(Status, ["Deleted", "Locked"])
.order_desc(UpdatedAt)
.limit(10)
.build();
let users: Vec<Map> = User::find(&query).await?;
Implementations§
Source§impl<E: Entity> Window<E>
impl<E: Entity> Window<E>
Sourcepub fn count(col: E::Column, partition: E::Column) -> Self
pub fn count(col: E::Column, partition: E::Column) -> Self
Constructs an instance for the window function COUNT
.
Sourcepub fn sum(col: E::Column, partition: E::Column) -> Self
pub fn sum(col: E::Column, partition: E::Column) -> Self
Constructs an instance for the window function SUM
.
Sourcepub fn avg(col: E::Column, partition: E::Column) -> Self
pub fn avg(col: E::Column, partition: E::Column) -> Self
Constructs an instance for the window function AVG
.
Sourcepub fn min(col: E::Column, partition: E::Column) -> Self
pub fn min(col: E::Column, partition: E::Column) -> Self
Constructs an instance for the window function MIN
.
Sourcepub fn max(col: E::Column, partition: E::Column) -> Self
pub fn max(col: E::Column, partition: E::Column) -> Self
Constructs an instance for the window function MAX
.
Sourcepub fn row_number(partition: E::Column) -> Self
pub fn row_number(partition: E::Column) -> Self
Constructs an instance for the window function DENSE_RANK
.
Sourcepub fn dense_rank(partition: E::Column) -> Self
pub fn dense_rank(partition: E::Column) -> Self
Constructs an instance for the window function DENSE_RANK
.
Sourcepub fn percent_rank(partition: E::Column) -> Self
pub fn percent_rank(partition: E::Column) -> Self
Constructs an instance for the window function PERCENT_RANK
.
Sourcepub fn cume_dist(partition: E::Column) -> Self
pub fn cume_dist(partition: E::Column) -> Self
Constructs an instance for the window function CUME_DIST
.
Sourcepub fn ntile(num_buckets: usize, partition: E::Column) -> Self
pub fn ntile(num_buckets: usize, partition: E::Column) -> Self
Constructs an instance for the window function NTILE
.
Sourcepub fn lag(col: E::Column, offset: usize, partition: E::Column) -> Self
pub fn lag(col: E::Column, offset: usize, partition: E::Column) -> Self
Constructs an instance for the window function LAG
.
Sourcepub fn lead(col: E::Column, offset: usize, partition: E::Column) -> Self
pub fn lead(col: E::Column, offset: usize, partition: E::Column) -> Self
Constructs an instance for the window function LEAD
.
Sourcepub fn first_value(col: E::Column, partition: E::Column) -> Self
pub fn first_value(col: E::Column, partition: E::Column) -> Self
Constructs an instance for the window function FIRST_VALUE
.
Sourcepub fn last_value(col: E::Column, partition: E::Column) -> Self
pub fn last_value(col: E::Column, partition: E::Column) -> Self
Constructs an instance for the window function LAST_VALUE
.
Sourcepub fn nth_value(col: E::Column, n: usize, partition: E::Column) -> Self
pub fn nth_value(col: E::Column, n: usize, partition: E::Column) -> Self
Constructs an instance for the window function NTH_VALUE
.
Sourcepub fn order_desc(self, col: E::Column) -> Self
pub fn order_desc(self, col: E::Column) -> Self
Sets the sort order with an descending order.
Trait Implementations§
impl<E: Copy + Entity> Copy for Window<E>
Auto Trait Implementations§
impl<E> Freeze for Window<E>
impl<E> RefUnwindSafe for Window<E>
impl<E> Send for Window<E>
impl<E> Sync for Window<E>
impl<E> Unpin for Window<E>
impl<E> UnwindSafe for Window<E>
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more