Repository navigation
feat(query): note.query and notesctl query for ADR-0037's Bases subset - #245
Merged
Merged
Conversation
Add note.query to the note domain (additive in protocol 1) and notesctl query. internal/query parses a base's YAML, checks the M5 subset (filters with and/or/not, properties with displayName, table and cards views) and compiles it to one SQL condition and ORDER BY over files LEFT JOIN notes, with every property key and literal bound. store.DB.RunQuery runs it; the engine serves it. Anything outside the subset is refused with its location, shown as an unshown column, or gives a view notice; never a wrong row. ADR-0037 is accepted. The contract is docs/specs/bases.md, the work order plan 0010, and design/vault.md gains a Queries section.
Fix the 7 blocking points of the cross-review at 745a40b, each with a test that fails without its fix (the snapshot fix with an AGENTS.md rule): integers fold and group without float64 loss; rows and total come from 1 statement; a base is sized by the bytes read; a bad second YAML document is refused; only the filters and keys read are checked; a list constant expands only in file.hasTag, containsAny and containsAll; calendar durations are tested across a DST change.
SQLite compares an integer with a real without rounding the integer; the fold now does the same with math/big, so 9007199254740993 == 9007199254740992.0 is false in both.
Contributor
Author
Cross-review record
|
bketelsen
approved these changes
Nov 17, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The first step of roadmap M5 (queries): notesd evaluates a subset of Obsidian Bases, per ADR-0037. M5's query done-when is that Dataview dashboards are rebuilt as
.basefiles and render. Every client (the desktop app, the web app, the later MCP toolquery_notesof ADR-0012) needs one evaluator in notesd, so this PR adds it first.note.queryinschema/rpc/note.yaml, additive in protocol 1 (make gen). Input:pathorsource,from,view,limit. Output: the view, every view's name and type, columns with display names, rows, groups,total, theunshowncolumn keys, anoticefor a view outside the subset, and a cards view'simage.internal/queryparses the YAML (yaml.Node, so errors name a location such asviews[0].filters.and[1]) and the statements. It folds constants (today(),now(), durations,date(),this.file.*) and compiles the filters,sortandgroupByto SQL overfiles LEFT JOIN notes. Every property key and literal is a bound parameter. Every condition is 0 or 1, never NULL. Anything outside the subset is refused with its location, or is an unshown column, or gives a view notice. Never a wrong row.store.DB.RunQueryruns it. No table, no migration.frostnotes_time, a deterministic SQL function, reads ISO 8601 frontmatter dates in notesd's time zone.notesctl query PATH|- [--view] [--limit] [--from] [--json].Queriessection indocs/design/vault.md, and ADR-0037 set to Accepted. One sentence of the ADR changes: listcontainsreadsjson_each, becausepropsrows lose the difference between5and"5".Risk tier
Risk tier: 2 — a new read-only RPC method and a SQL compiler. No path in
.github/risk-paths.jsonmatches. The method only reads the index. No base text reaches SQL text:FuzzCompilechecks this.Docs housekeeping
TEMPLATE.md(specs/bases.md,plans/0010-m5-queries.md)docs/README.mdVerification
make cigreen on the host at the code of this head (verify,make ui-checkin nsl with Biome, tsc and Vitest at 96 files,make desktop-build, the race run). After the run, onlydocs/specs/bases.mdchanged (the Fixtures paragraph).make genrun andmake gen-checkgreeninternal/query:this, columns, sort, groups, limit and notices.not: [x]returns exactly the rows thatxdoes not.FuzzCompileandBenchmarkQuery: on 1,000 generated notes, a filter with a sort takes 5.0 ms, a group 11.1 ms, a text search 13.9 ms.internal/rpctest, the engine test (thisfrompathandfrom, param errors) and anotesctl querytest.