use crate::db::query::admission::{
DEFAULT_BOUNDED_READ_MAX_ROWS, DEFAULT_BOUNDED_READ_RESPONSE_BYTES,
};
pub(in crate::db::query) const PUBLIC_PAGE_DEFAULT_ROWS: u32 = DEFAULT_BOUNDED_READ_MAX_ROWS;
pub(in crate::db::query) const PUBLIC_PAGE_MAX_ROWS: u32 = DEFAULT_BOUNDED_READ_MAX_ROWS;
pub(in crate::db::query) const PUBLIC_PAGE_MAX_RESPONSE_BYTES: u32 =
DEFAULT_BOUNDED_READ_RESPONSE_BYTES;
pub(in crate::db::query) const COMPLETE_SMALL_MAX_ROWS: u32 = DEFAULT_BOUNDED_READ_MAX_ROWS;
pub(in crate::db::query) const COMPLETE_SMALL_LOOKAHEAD_ROWS: u32 = 1;
pub(in crate::db::query) const COMPLETE_SMALL_EXECUTION_LIMIT: u32 =
COMPLETE_SMALL_MAX_ROWS + COMPLETE_SMALL_LOOKAHEAD_ROWS;
pub(in crate::db::query) const ADMIN_BATCH_ROWS: u32 = DEFAULT_BOUNDED_READ_MAX_ROWS;
#[derive(Clone, Debug, Default, Eq, PartialEq)]
pub struct PageRequest {
limit: Option<u32>,
cursor: Option<String>,
}
impl PageRequest {
#[must_use]
pub const fn new() -> Self {
Self {
limit: None,
cursor: None,
}
}
#[must_use]
pub const fn first(limit: u32) -> Self {
Self {
limit: Some(limit),
cursor: None,
}
}
#[must_use]
pub fn next(limit: u32, cursor: impl Into<String>) -> Self {
Self {
limit: Some(limit),
cursor: Some(cursor.into()),
}
}
#[must_use]
pub const fn with_limit(mut self, limit: u32) -> Self {
self.limit = Some(limit);
self
}
#[must_use]
pub fn with_cursor(mut self, cursor: impl Into<String>) -> Self {
self.cursor = Some(cursor.into());
self
}
#[must_use]
pub const fn limit(&self) -> Option<u32> {
self.limit
}
#[must_use]
pub fn cursor(&self) -> Option<&str> {
self.cursor.as_deref()
}
pub(in crate::db::query) const fn effective_limit(&self) -> u32 {
match self.limit {
Some(0) => 1,
Some(limit) if limit > PUBLIC_PAGE_MAX_ROWS => PUBLIC_PAGE_MAX_ROWS,
Some(limit) => limit,
None => PUBLIC_PAGE_DEFAULT_ROWS,
}
}
pub(in crate::db::query) fn into_cursor(self) -> Option<String> {
self.cursor
}
}
#[derive(Clone, Debug, Default, Eq, PartialEq)]
pub struct AdminBatchRequest {
cursor: Option<String>,
}
impl AdminBatchRequest {
#[must_use]
pub const fn new() -> Self {
Self { cursor: None }
}
#[must_use]
pub fn next(cursor: impl Into<String>) -> Self {
Self {
cursor: Some(cursor.into()),
}
}
#[must_use]
pub fn with_cursor(mut self, cursor: impl Into<String>) -> Self {
self.cursor = Some(cursor.into());
self
}
#[must_use]
pub fn cursor(&self) -> Option<&str> {
self.cursor.as_deref()
}
pub(in crate::db::query) fn into_cursor(self) -> Option<String> {
self.cursor
}
}