Skip to main content

ic_db_cli/
lib.rs

1//! Transport types shared by the local DB console and its fixture canister.
2#![forbid(unsafe_code)]
3
4#[cfg(feature = "host")]
5pub mod host;
6
7/// A local query result, in the fixture's positional Wire field order.
8#[derive(Debug, serde::Deserialize, serde::Serialize)]
9pub struct ConsolePage {
10    /// Display column names.
11    pub columns: Vec<String>,
12    /// Display cells in column order.
13    pub rows: Vec<Vec<String>>,
14    /// Encoded continuation for a paged read.
15    pub next: Option<Vec<u8>>,
16    /// Examined query candidates.
17    pub examined: u32,
18    /// Fetched source rows.
19    pub fetched: u32,
20    /// Encoded result bytes before transport framing.
21    pub output_bytes: u32,
22}
23
24/// Row predicates carried by the local query and retained-aggregate commands.
25#[derive(Clone, Debug, Default, serde::Deserialize, serde::Serialize)]
26pub struct RowFilters {
27    /// Lower bound, upper bound, prefix, suffix and substring on BinaryObject.payload.
28    pub payload: [Option<Vec<u8>>; 5],
29    /// Left field, comparison, right field.
30    pub compare: Option<[String; 3]>,
31    /// Field, comparison and length threshold.
32    pub length: Option<(String, String, u32)>,
33    /// Require a value in this optional field.
34    pub present: Option<String>,
35    /// Require absence in this optional field.
36    pub absent: Option<String>,
37    /// Field, comparison and exact UTF-8 literal.
38    pub text: Option<[String; 3]>,
39    /// Field and Boolean equality operand.
40    pub boolean: Option<(String, bool)>,
41    /// Field, inclusive lower field and inclusive upper field.
42    pub between_fields: Option<[String; 3]>,
43    /// Field, lower field and upper field for the strict outside-range comparison.
44    pub not_between_fields: Option<[String; 3]>,
45}
46
47/// Selection shared by the private retained fixture when starting and resuming a job.
48pub type RetainedSelection = (
49    String,
50    String,
51    (Option<u64>, Option<u64>, Option<u64>),
52    u32,
53    (Option<String>, Option<String>),
54    Option<String>,
55    RowFilters,
56    (Vec<String>, bool),
57);
58
59/// Display columns, rows and optional next cursor of a completed retained query.
60pub type RetainedOutput = (Vec<String>, Vec<Vec<String>>, Option<Vec<u8>>);
61
62/// Progress reported by the local fixture after one retained query step.
63#[derive(Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
64pub struct RetainedProgress {
65    /// Last saved step.
66    pub sequence: u64,
67    /// Candidates examined so far.
68    pub examined: u64,
69    /// Input bytes examined so far.
70    pub input_bytes: u64,
71    /// Encoded result bytes in this step.
72    pub output_bytes: u64,
73    /// Current phase and any completed result.
74    pub phase: RetainedPhase,
75}
76
77/// Only a completed job has output.
78#[derive(Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
79pub enum RetainedPhase {
80    /// Additional input remains.
81    Running,
82    /// Completed rows and continuation.
83    Complete(RetainedOutput),
84    /// Source rows changed.
85    Invalidated,
86    /// Job lifetime elapsed.
87    Expired,
88}
89
90impl RetainedPhase {
91    /// Name used by console progress messages.
92    #[must_use]
93    pub const fn label(&self) -> &'static str {
94        match self {
95            Self::Running => "Running",
96            Self::Complete(_) => "Complete",
97            Self::Invalidated => "Invalidated",
98            Self::Expired => "Expired",
99        }
100    }
101}