8000 feat: prepared queries with plain JS bind values (minigraf#181) by adityamukho · Pull Request #18 · project-minigraf/minigraf-node · GitHub
[go: up one dir, main page]

Skip to content

feat: prepared queries with plain JS bind values (minigraf#181) - #18

Merged
adityamukho merged 3 commits into
v3from
feat/181-prepared-ffi
Oct 24, 2026
Merged

adityamukho merged 3 commits into
v3from
feat/181-prepared-ffi

Conversation

@adityamukho
Copy link
Copy Markdown
Contributor

PR 4 (node) of project-minigraf/minigraf#181 (spec §4.2, §5, §6, §7.2; plan step 15).

  • MiniGrafDb.prepare(text) → PreparedQuery with execute(bindings) (JSON) and query(bindings) (Cursor), exported from minigraf.js and index.js. index.d.ts regenerated by napi build.
  • Bindings: booleans, strings, null, bigints and numbers (an integer when Number.isInteger accepts it, else a float; outside i64 → API-017) bind as values. The typed forms are FactValue ({ type: 'float', value: 2 }, 'keyword', 'ref', ...), { type: 'entity' }, { type: 'txCount' | 'timestamp' } (number or bigint) and { type: 'anyValidTime' }. A value that isn't a bind value throws a real TypeError (thrown on the env and returned as PendingException); a throwing getter propagates its own error.
  • Lifetime (spec §6): MiniGrafDb keeps a weak list of its prepared queries. close() empties them before dropping the database, so the documented reopen works. prepare holds the db lock while it adds to the list, so a close() can't miss one. A prepared query used after close() throws [API-018] database is closed.
  • CI and npm test also run test/prepared.test.mjs. Consumer contract: a prepared query run with plain and typed values. README: a Prepared queries section.

Tests (local, Node 24): 21/21, 7 new: repeated runs checked per row, every plain and typed form, the 2 vs {type:'float'} rule, the cursor, TypeErrors, API-017/018/022/023/024/005, reopen after close() with a prepared query alive. The contract passes. Clippy clean. Codex: one finding (getter errors were swallowed), fixed.

Found while checking spec §6: an open cursor or fact log already blocks reopening after close(). Filed as #17, not fixed here.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Urda7FD9CYYoxdeGGJa11x

adityamukho and others added 3 commits October 24, 2026 15:03
Core pin 5f2ba46e (minigraf#738). MiniGrafDb.prepare -> PreparedQuery
with execute(bindings) / query(bindings): booleans, numbers (integer
when Number.isInteger), bigints, strings and null bind as values;
FactValue and {type: entity|txCount|timestamp|anyValidTime} forms for
the rest; anything else is a TypeError. close() empties every prepared
query, so the path reopens; a prepared query used after close() throws
API-018.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Urda7FD9CYYoxdeGGJa11x
@adityamukho
adityamukho merged commit 3897ae4 into v3 Oct 24, 2026
14 checks passed
@adityamukho
adityamukho deleted the feat/181-prepared-ffi branch October 24, 2026 10:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

0