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) — 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,
always layer-scoped when with_layer is set, so an --in <layer>
scope confines the sidecar walk to that layer’s subtree
(O(entities-in-layer), the interactive-loop contract):
- a
typepredicate reads the sidecars across the named layer (or the whole store when unscoped) and filters by the frontmattertype. The folder layout is convention, not enforcement (SPEC), so a record whosetypeis filed outside that type’s canonical layer — acontactinsources/, a customscreenshotthat only ever lives insources/— is still found, and--type X --in <other-layer>returns exactly the records of that type filed under the other layer rather than always being empty; - otherwise the first
whereclause picks the sidecars and pre-filters, scoped to the layer when set; - otherwise (a layer scope but no
type/where) the layer’s own sidecar records are the candidate set, so--in <layer>on its own enumerates that layer instead of silently returning empty.
Every remaining predicate is then applied in memory over the returned records — no extra sidecar reads, no walk.
A fully bare query (no type, no where, no layer) constrains nothing
and has no selective candidate set, so it returns an empty result.