pub struct PaginationOptions<T = ()>where
T: OrderByOptions,{
pub page: usize,
pub items_per_page: usize,
pub order_by: T,
}Expand description
Struct representing pagination options.
§Examples
let options = PaginationOptions::new().page(1).items_per_page(20);Fields§
§page: usizePage number.
- If the value is
0, it will default to1. - If the value exceeds the maximum page number, it will be considered as the maximum page number.
Default: 1.
items_per_page: usizeNumber of items per page.
- If the value is
0, it means query all items in a single page.
Default: 0.
order_by: TOrdering options which has to implement the OrderByOptions trait.
Default: ().
Implementations§
Source§impl PaginationOptions
impl PaginationOptions
Sourcepub const fn new() -> PaginationOptions
pub const fn new() -> PaginationOptions
Create a new PaginationOptions.
let options = PaginationOptions::new();
// equals to
let options = PaginationOptions {
page: 1,
items_per_page: 0,
order_by: (),
};Source§impl<T> PaginationOptions<T>where
T: OrderByOptions,
impl<T> PaginationOptions<T>where
T: OrderByOptions,
Sourcepub const fn page(self, page: usize) -> PaginationOptions<T>
pub const fn page(self, page: usize) -> PaginationOptions<T>
Set the page number.
- If the value is
0, it will be considered as1. - If the value exceeds the maximum page number, it will be considered as the maximum page number.
Sourcepub const fn items_per_page(self, items_per_page: usize) -> PaginationOptions<T>
pub const fn items_per_page(self, items_per_page: usize) -> PaginationOptions<T>
Set the number of items per page.
- If the value is
0, it means query all items in a single page.
Sourcepub fn order_by(self, order_by: T) -> PaginationOptions<T>
pub fn order_by(self, order_by: T) -> PaginationOptions<T>
Set the ordering options which has to implement the OrderByOptions trait.
Source§impl<T> PaginationOptions<T>where
T: OrderByOptions,
impl<T> PaginationOptions<T>where
T: OrderByOptions,
Sourcepub fn to_mysql_limit_offset<'a>(&self, s: &'a mut String) -> &'a str
pub fn to_mysql_limit_offset<'a>(&self, s: &'a mut String) -> &'a str
Generate a LIMIT with OFFSET clause for MySQL.
If limit() is Some(n),
LIMIT <limit()> [OFFSET <offset()>]If offset() is not zero,
[LIMIT <limit()>] OFFSET <offset()>Source§impl<T> PaginationOptions<T>where
T: OrderByOptions,
impl<T> PaginationOptions<T>where
T: OrderByOptions,
Sourcepub fn to_sqlite_limit_offset<'a>(&self, s: &'a mut String) -> &'a str
pub fn to_sqlite_limit_offset<'a>(&self, s: &'a mut String) -> &'a str
Generate a LIMIT with OFFSET clause for SQLite.
If limit() is Some(n),
LIMIT <limit()> [OFFSET <offset()>]If offset() is not zero,
[LIMIT <limit()>] OFFSET <offset()>Source§impl<T> PaginationOptions<T>where
T: OrderByOptions,
impl<T> PaginationOptions<T>where
T: OrderByOptions,
Sourcepub fn to_mssql_limit_offset<'a>(&self, s: &'a mut String) -> &'a str
pub fn to_mssql_limit_offset<'a>(&self, s: &'a mut String) -> &'a str
Generate a OFFSET with FETCH clause for Microsoft SQL Server.
If limit() is Some(n) or offset() is not zero,
OFFSET <offset()> ROWS [FETCH NEXT <limit()> ROWS ONLY]Source§impl<T> PaginationOptions<T>where
T: OrderByOptions,
impl<T> PaginationOptions<T>where
T: OrderByOptions,
Sourcepub fn to_mssql2008_limit_offset<'a>(
&self,
row_number_column_name: impl AsRef<str>,
s: &'a mut String,
) -> &'a str
pub fn to_mssql2008_limit_offset<'a>( &self, row_number_column_name: impl AsRef<str>, s: &'a mut String, ) -> &'a str
Generate a WHERE clause for Microsoft SQL Server 2008 and earlier (used for check the row number).
If limit() is Some(n),
WHERE [<row_number_column_name>] <= <limit()>If offset() is not zero,
WHERE [<row_number_column_name>] > <offset()>If both above are true,
WHERE [<row_number_column_name>] BETWEEN (<offset() + 1>) AND <offset() + limit()>Trait Implementations§
Source§impl<T> Clone for PaginationOptions<T>where
T: Clone + OrderByOptions,
impl<T> Clone for PaginationOptions<T>where
T: Clone + OrderByOptions,
Source§fn clone(&self) -> PaginationOptions<T>
fn clone(&self) -> PaginationOptions<T>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<T> Debug for PaginationOptions<T>where
T: Debug + OrderByOptions,
impl<T> Debug for PaginationOptions<T>where
T: Debug + OrderByOptions,
Source§impl<T> Default for PaginationOptions<T>where
T: OrderByOptions,
impl<T> Default for PaginationOptions<T>where
T: OrderByOptions,
Source§fn default() -> PaginationOptions<T>
fn default() -> PaginationOptions<T>
Create a new PaginationOptions<T>.
let options = <PaginationOptions<()>>::default();
// equals to
let options = PaginationOptions {
page: 1,
items_per_page: 0,
order_by: (),
};