toasty_core/driver/operation/query_pk.rs
1use super::{Operation, Pagination};
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: None,
26/// order: None,
27/// };
28/// let operation: Operation = op.into();
29/// ```
30#[derive(Debug, Clone)]
31pub struct QueryPk {
32 /// The table to query.
33 pub table: TableId,
34
35 /// Index to query. `None` means the primary key; `Some(id)` means a
36 /// secondary index.
37 pub index: Option<IndexId>,
38
39 /// Which columns to include in the returned rows.
40 pub select: Vec<ColumnId>,
41
42 /// Filter expression applied against the index key columns.
43 pub pk_filter: stmt::Expr,
44
45 /// Optional post-filter applied to rows after the index scan, before
46 /// returning results to the caller.
47 pub filter: Option<stmt::Expr>,
48
49 /// Limit and pagination bounds for this query. `None` means unbounded.
50 pub limit: Option<Pagination>,
51
52 /// Sort key ordering direction for tables with a composite primary key.
53 /// `None` uses the driver's default ordering.
54 pub order: Option<stmt::Direction>,
55}
56
57impl From<QueryPk> for Operation {
58 fn from(value: QueryPk) -> Self {
59 Self::QueryPk(value)
60 }
61}