8000 feat(prepared): Phase 7.8 — prepared statements by adityamukho · Pull Request #91 · project-minigraf/minigraf · GitHub
[go: up one dir, main page]

Skip to content

feat(prepared): Phase 7.8 — prepared statements - #91

Merged
adityamukho merged 16 commits into
mainfrom
feature/phase-7-8-prepared-statements
Apr 4, 2026
Merged

adityamukho merged 16 commits into
mainfrom
feature/phase-7-8-prepared-statements

Conversation

@adityamukho
Copy link
Copy Markdown
Collaborator

Summary

  • Adds Minigraf::prepare(query_str) → PreparedQuery — parse and plan a query once with named $slot bind slots
  • Adds PreparedQuery::execute(&[(&str, BindValue)]) → QueryResult — substitute concrete values and run, with full type checking per slot position
  • Re-exports BindValue and PreparedQuery from the crate root for ergonomic use

Approach

Option A (inline substitution): deep-clone the AST at execute() time, walk and replace BindSlot/Slot nodes with concrete values, pass the filled query to the existing executor unchanged. The executor, optimizer, matcher, evaluator, and stratification modules are untouched beyond panic guards for unsubstituted slots.

Changes

  • types.rs — 4 new variants: EdnValue::BindSlot, AsOf::Slot, ValidAt::Slot, Expr::Slot
  • parser.rs — tokenise $identifier, parse to AST slot variants; Expr::Slot returns vec![] in expr_vars
  • executor.rs / storage.rs — panic guards at all temporal and expression match sites
  • prepared.rs (new) — BindValue, PreparedQuery, substitution logic, 19 unit tests
  • db.rs — Minigraf::prepare() with non-query rejection
  • lib.rs — re-exports
  • tests/prepared_statements_test.rs — 17 integration tests covering all slot positions, error paths, and plan reuse

Test Plan

  • cargo test — 796 tests, 0 failures (was 753 before this phase)
  • cargo test --test prepared_statements_test — all 17 integration tests pass
  • cargo clippy — no warnings
  • cargo fmt --check — clean

Closes #88

🤖 Generated with Claude Code

adityamukho and others added 13 commits April 4, 2026 10:30
Adds EdnValue::BindSlot(String), AsOf::Slot(String), ValidAt::Slot(String),
and Expr::Slot(String) — parse-only variants representing $name tokens in
prepared query templates. Must be substituted before reaching the executor.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…dSlot variants

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…tion, and substitution

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
… helpers

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…n/edn fields

Replace three mem::replace(&mut field, EdnValue::Nil) patterns with
borrow-then-clone, so non-BindSlot values (variables, literals) are
never overwritten with Nil before the match is tested.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…alue

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Comment thread src/query/datalog/executor.rs Fixed
Comment thread src/query/datalog/executor.rs Fixed
Comment thread src/query/datalog/executor.rs Fixed
Comment thread src/query/datalog/executor.rs Fixed
@codecov
codecov Bot commented Apr 4, 2026 •
Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 64.51613% with 77 lines in your changes missing coverage. Please review.
✅ Project coverage is 83.73%. Comparing base (cb2985f) to head (611ed81).
⚠️ Report is 17 commits behind head on main.

Files with missing lines Patch % Lines
src/query/datalog/prepared.rs 61.95% 70 Missing ⚠️
src/query/datalog/executor.rs 0.00% 5 Missing ⚠️
src/graph/storage.rs 0.00% 1 Missing ⚠️
src/query/datalog/parser.rs 93.75% 1 Missing ⚠️

❌ Your patch status has failed because the patch coverage (64.51%) is below the target coverage (75.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main      #91      +/-   ##
==========================================
- Coverage   84.61%   83.73%   -0.89%     
==========================================
  Files          25       26       +1     
  Lines        4569     4788     +219     
==========================================
+ Hits         3866     4009     +143     
- Misses        703      779      +76     
Files with missing lines Coverage Δ
src/db.rs 91.46% <100.00%> (+0.33%) ⬆️
src/query/datalog/types.rs 87.58% <ø> (ø)
src/graph/storage.rs 86.95% <0.00%> (+0.05%) ⬆️
src/query/datalog/parser.rs 86.21% <93.75%> (+0.15%) ⬆️
src/query/datalog/executor.rs 93.82% <0.00%> (-0.72%) ⬇️
src/query/datalog/prepared.rs 61.95% <61.95%> (ø)

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@adityamukho
adityamukho merged commit d9d0454 into main Apr 4, 2026
14 of 15 checks passed
@adityamukho
adityamukho deleted the feature/phase-7-8-prepared-statements branch April 4, 2026 08:10
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.

2 participants

0