pub struct Query { /* private fields */ }Expand description
A composable, sidecar-backed filter over a store’s records.
Build with Query::new and the with_* methods, then Query::execute.
Multiple Query::with_where clauses AND together (intersection over the
sidecar records).
Implementations§
Source§impl Query
impl Query
Sourcepub fn with_type(self, type_: &str) -> Self
pub fn with_type(self, type_: &str) -> Self
Restrict to a single type (frontmatter type predicate).
Setting it again replaces the previous value — a query has at most one
type (a record carries exactly one type, so two types would never
intersect).
Sourcepub fn with_layer(self, layer: Layer) -> Self
pub fn with_layer(self, layer: Layer) -> Self
Restrict to one layer (Sources / Records / Wiki) — scopes which
sidecars’ records survive. Setting it again replaces the previous layer.
Sourcepub fn with_where(self, key: &str, value: &str) -> Self
pub fn with_where(self, key: &str, value: &str) -> Self
Add a key=value frontmatter predicate; chains as AND with any others
(intersection over the sidecar records). Repeating the same key adds a
second clause — both must hold — rather than replacing the first.
Sourcepub fn execute(&self, store: &Store) -> Result<Vec<IndexRecord>, StoreError>
pub fn execute(&self, store: &Store) -> Result<Vec<IndexRecord>, StoreError>
Resolve the query against the relevant type-folder index.jsonl
sidecar(s) and return the matching IndexRecords — complete, one
sequential read per type-folder, no whole-store walk.
The candidate set comes from the most selective frozen sidecar reader:
Store::find_by_type when a type is set (one type-folder’s
sidecars), otherwise Store::find_by_where_in on the first where
clause — and that reader is layer-scoped when with_layer is set,
so a --where-only query reads only the named layer’s sidecars instead
of the whole store (O(entities-in-layer), the interactive-loop contract).
The layer scope and every remaining predicate are then applied in memory
over the returned records — no extra sidecar reads, no walk.
A query that constrains neither type nor any where clause selects no
sidecar (a bare or layer-only query has no walk-free candidate set under
the sidecar API) and returns an empty result; the CLI always supplies a
--type or a --where.