toasty_core/driver/operation/query_pk.rs
1use super::Operation;
2use crate::{
3 schema::db::{ColumnId, IndexId, TableId},
4 stmt,
5};
6
7/// Queries a table by primary key (or secondary index) with optional filtering,
8/// ordering, and pagination.
9///
10/// This is the primary read operation for key-value drivers. The driver applies
11/// `pk_filter` against the index, then applies the optional post-`filter`, and
12/// returns up to `limit` rows in the requested `order`.
13///
14/// # Examples
15///
16/// ```ignore
17/// use toasty_core::driver::operation::{QueryPk, Operation};
18///
19/// let op = QueryPk {
20/// table: table_id,
21/// index: None, // query the primary key
22/// select: vec![col_a, col_b],
23/// pk_filter: pk_expr,
24/// filter: None,
25/// limit: Some(10),
26/// order: None,
27/// cursor: None,
28/// };
29/// let operation: Operation = op.into();
30/// ```
31#[derive(Debug, Clone)]
32pub struct QueryPk {
33 /// The table to query.
34 pub table: TableId,
35
36 /// Index to query. `None` means the primary key; `Some(id)` means a
37 /// secondary index.
38 pub index: Option<IndexId>,
39
40 /// Which columns to include in the returned rows.
41 pub select: Vec<ColumnId>,
42
43 /// Filter expression applied against the index key columns.
44 pub pk_filter: stmt::Expr,
45
46 /// Optional post-filter applied to rows after the index scan, before
47 /// returning results to the caller.
48 pub filter: Option<stmt::Expr>,
49
50 /// Maximum number of rows to return. `None` means no limit.
51 pub limit: Option<i64>,
52
53 /// Sort key ordering direction for tables with a composite primary key.
54 /// `None` uses the driver's default ordering.
55 pub order: Option<stmt::Direction>,
56
57 /// Pagination cursor. Contains the serialized key of the last item from a
58 /// previous page of results. When set, the query resumes after this key.
59 pub cursor: Option<stmt::Value>,
60}
61
62impl From<QueryPk> for Operation {
63 fn from(value: QueryPk) -> Self {
64 Self::QueryPk(value)
65 }
66}