toasty_core/stmt/
limit.rs

1use super::Expr;
2
3/// A `LIMIT` clause restricting the number of rows returned by a query.
4///
5/// Two strategies are supported:
6///
7/// * [`Limit::Cursor`] — keyset-based (cursor) pagination, used by
8///   [`Paginate`](crate::stmt::Paginate). The engine will build pagination
9///   cursors and track whether more pages exist.
10/// * [`Limit::Offset`] — traditional SQL `LIMIT … OFFSET …`. No pagination
11///   metadata is produced.
12#[derive(Debug, Clone, PartialEq)]
13pub enum Limit {
14    /// Cursor-based (keyset) pagination.
15    Cursor(LimitCursor),
16
17    /// Traditional SQL `LIMIT` with optional count-based `OFFSET`.
18    Offset(LimitOffset),
19}
20
21/// Cursor-based pagination parameters.
22///
23/// `page_size` controls how many rows are returned per page. `after` is `None`
24/// for the first page and `Some(cursor)` for subsequent pages.
25#[derive(Debug, Clone, PartialEq)]
26pub struct LimitCursor {
27    /// Number of rows per page.
28    pub page_size: Expr,
29
30    /// Cursor value to resume after. `None` on the first page.
31    pub after: Option<Expr>,
32}
33
34/// Traditional SQL `LIMIT … OFFSET …` parameters.
35#[derive(Debug, Clone, PartialEq)]
36pub struct LimitOffset {
37    /// The maximum number of rows to return.
38    pub limit: Expr,
39
40    /// Optional count-based offset (skip this many rows).
41    pub offset: Option<Expr>,
42}