use serde::{Deserialize, Serialize};
use super::address::{DimensionVector, RevisionId, SpaceId};
use super::snapshot::SnapshotId;
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SpatialRange {
pub min: DimensionVector,
pub max: DimensionVector,
}
impl SpatialRange {
pub fn new(min: DimensionVector, max: DimensionVector) -> Self {
assert_eq!(min.dims(), max.dims(), "Range bounds must have equal dimensions");
Self { min, max }
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Query {
pub space: SpaceId,
pub snapshot: SnapshotId,
pub range: Option<SpatialRange>,
pub key_range: Option<(u128, u128)>,
pub as_of: Option<RevisionId>,
pub include_tombstones: bool,
}
impl Query {
pub fn new(space: SpaceId, snapshot: SnapshotId) -> Self {
Self {
space,
snapshot,
range: None,
key_range: None,
as_of: None,
include_tombstones: false,
}
}
pub fn with_range(mut self, range: SpatialRange) -> Self {
self.range = Some(range);
self
}
pub fn with_key_range(mut self, lo: u128, hi: u128) -> Self {
self.key_range = Some((lo, hi));
self
}
pub fn as_of(mut self, revision: RevisionId) -> Self {
self.as_of = Some(revision);
self
}
pub fn include_tombstones(mut self) -> Self {
self.include_tombstones = true;
self
}
pub fn with_bounds(self, min: Vec<u32>, max: Vec<u32>) -> Self {
self.with_range(SpatialRange::new(
DimensionVector::new(min),
DimensionVector::new(max),
))
}
}