infinite_db/infinitedb_core/
query.rs1use serde::{Deserialize, Serialize};
2use super::address::{DimensionVector, RevisionId, SpaceId};
3use super::snapshot::SnapshotId;
4
5#[derive(Debug, Clone, Serialize, Deserialize)]
8pub struct SpatialRange {
9 pub min: DimensionVector,
10 pub max: DimensionVector,
11}
12
13impl SpatialRange {
14 pub fn new(min: DimensionVector, max: DimensionVector) -> Self {
16 assert_eq!(min.dims(), max.dims(), "Range bounds must have equal dimensions");
17 Self { min, max }
18 }
19}
20
21#[derive(Debug, Clone, Serialize, Deserialize)]
24pub struct Query {
25 pub space: SpaceId,
26 pub snapshot: SnapshotId,
27 pub range: Option<SpatialRange>,
29 pub key_range: Option<(u128, u128)>,
32 pub as_of: Option<RevisionId>,
35 pub include_tombstones: bool,
37}
38
39impl Query {
40 pub fn new(space: SpaceId, snapshot: SnapshotId) -> Self {
42 Self {
43 space,
44 snapshot,
45 range: None,
46 key_range: None,
47 as_of: None,
48 include_tombstones: false,
49 }
50 }
51
52 pub fn with_range(mut self, range: SpatialRange) -> Self {
54 self.range = Some(range);
55 self
56 }
57
58 pub fn with_key_range(mut self, lo: u128, hi: u128) -> Self {
60 self.key_range = Some((lo, hi));
61 self
62 }
63
64 pub fn as_of(mut self, revision: RevisionId) -> Self {
66 self.as_of = Some(revision);
67 self
68 }
69
70 pub fn include_tombstones(mut self) -> Self {
72 self.include_tombstones = true;
73 self
74 }
75
76 pub fn with_bounds(self, min: Vec<u32>, max: Vec<u32>) -> Self {
78 self.with_range(SpatialRange::new(
79 DimensionVector::new(min),
80 DimensionVector::new(max),
81 ))
82 }
83}