icydb_core/db/query/
read_intent.rs1use crate::db::query::admission::{
7 DEFAULT_BOUNDED_READ_MAX_ROWS, DEFAULT_BOUNDED_READ_RESPONSE_BYTES,
8};
9use candid::CandidType;
10use serde::Deserialize;
11
12pub(in crate::db::query) const PUBLIC_PAGE_DEFAULT_ROWS: u32 = DEFAULT_BOUNDED_READ_MAX_ROWS;
13pub(in crate::db::query) const PUBLIC_PAGE_MAX_ROWS: u32 = DEFAULT_BOUNDED_READ_MAX_ROWS;
14pub(in crate::db::query) const PUBLIC_PAGE_MAX_RESPONSE_BYTES: u32 =
15 DEFAULT_BOUNDED_READ_RESPONSE_BYTES;
16
17pub(in crate::db::query) const COMPLETE_SMALL_MAX_ROWS: u32 = DEFAULT_BOUNDED_READ_MAX_ROWS;
18pub(in crate::db::query) const COMPLETE_SMALL_LOOKAHEAD_ROWS: u32 = 1;
19pub(in crate::db::query) const COMPLETE_SMALL_EXECUTION_LIMIT: u32 =
20 COMPLETE_SMALL_MAX_ROWS + COMPLETE_SMALL_LOOKAHEAD_ROWS;
21pub(in crate::db::query) const ADMIN_BATCH_ROWS: u32 = DEFAULT_BOUNDED_READ_MAX_ROWS;
22
23#[derive(CandidType, Clone, Copy, Debug, Default, Deserialize, Eq, PartialEq)]
28pub enum ReadIntentKind {
29 #[default]
31 Unspecified,
32
33 BoundedRowWindow,
35
36 ExistenceCheck,
38
39 PublicPage,
41
42 CompleteSmallSet,
44
45 ExactAggregate,
47
48 TrustedAdminBatch,
50}
51
52#[derive(Clone, Debug, Default, Eq, PartialEq)]
57pub(in crate::db::query) struct PageRequest {
58 limit: Option<u32>,
59 cursor: Option<String>,
60}
61
62impl PageRequest {
63 #[must_use]
65 pub(in crate::db::query) const fn first(limit: u32) -> Self {
66 Self {
67 limit: Some(limit),
68 cursor: None,
69 }
70 }
71
72 #[must_use]
74 pub(in crate::db::query) fn next(limit: u32, cursor: impl Into<String>) -> Self {
75 Self {
76 limit: Some(limit),
77 cursor: Some(cursor.into()),
78 }
79 }
80
81 pub(in crate::db::query) const fn effective_limit(&self) -> u32 {
82 match self.limit {
83 Some(0) => 1,
84 Some(limit) if limit > PUBLIC_PAGE_MAX_ROWS => PUBLIC_PAGE_MAX_ROWS,
85 Some(limit) => limit,
86 None => PUBLIC_PAGE_DEFAULT_ROWS,
87 }
88 }
89
90 pub(in crate::db::query) fn into_cursor(self) -> Option<String> {
91 self.cursor
92 }
93}
94
95#[derive(Clone, Debug, Default, Eq, PartialEq)]
100pub struct AdminBatchRequest {
101 cursor: Option<String>,
102}
103
104impl AdminBatchRequest {
105 #[must_use]
107 pub const fn new() -> Self {
108 Self { cursor: None }
109 }
110
111 #[must_use]
113 pub fn next(cursor: impl Into<String>) -> Self {
114 Self {
115 cursor: Some(cursor.into()),
116 }
117 }
118
119 #[must_use]
121 pub fn with_cursor(mut self, cursor: impl Into<String>) -> Self {
122 self.cursor = Some(cursor.into());
123 self
124 }
125
126 #[must_use]
128 pub fn cursor(&self) -> Option<&str> {
129 self.cursor.as_deref()
130 }
131
132 pub(in crate::db::query) fn into_cursor(self) -> Option<String> {
133 self.cursor
134 }
135}