Skip to content

feat: add callable parameterized compiled queries - #241

Merged
andrewzolotukhin merged 1 commit into
developmentfrom
feat/compiled-parameter-queries
Oct 3, 2026
Merged

andrewzolotukhin merged 1 commit into
developmentfrom
feat/compiled-parameter-queries

Conversation

@andrewzolotukhin

Copy link
Copy Markdown
Contributor

Named parameter('name') placeholders now turn schema-backed PostgreSQL SELECTs into callable queries. Argument types come from the selected columns, and distinct names become positional arguments in construction order. Repeated names share one argument.

const findUsers = query(knex, UserSchema)
    .where(t => t.firstName, parameter('name'))
    .where(t => t.age, '>=', parameter('minimumAge'));

await findUsers('John', 18);
await findUsers('Jane', 30);
findUsers.toSQL('John', 18); // SQL and bindings without execution
findUsers.query('John', 18); // ordinary composable bound reader

The first invocation or SQL inspection caches the SELECT statement, binding slots and decoder. Later calls use fresh bindings through Knex's normal runner without rebuilding the statement. Immutable shape derivatives have separate plans; transaction derivatives from the same client share a plan. Captured selectors and customizers are never replayed during binding.

Includes grouped predicates, fixed membership/range slots, alias joins, typed relations, STI/CTI customizers, storage-aware Date/exact-numeric/JSON arguments, preserved null semantics, and ORM identity tracking. Unbound terminals/writes and unsupported placeholder positions are rejected. This covers fixed-shape SELECTs; it does not manage named server-side prepared statements or cache results.

Updates both package guides and documentation pages, removes completed F08 from the candidate list, and includes minor changesets for knex-schema and ORM.

Validation:

  • npm run lint
  • npm run build
  • npm run test (4,748 tests; no type errors)
  • Both documentation-site typechecks
  • Full PostgreSQL query integration suite (94 tests)
  • Parameter navigation/hover regression coverage for TypeScript and checked JavaScript
  • Instrumented compilation/callback tests, concurrent execution, transactions, and ORM tracking
  • npm run bench -- --project benchmarks libs/benchmarks/src/compiled-query.bench.ts separates construction, first compilation, warmed binding and runner/decoder overhead without database latency

@andrewzolotukhin
andrewzolotukhin merged commit f165dde into development Oct 3, 2026
3 checks passed
@andrewzolotukhin
andrewzolotukhin deleted the feat/compiled-parameter-queries branch October 3, 2026 11:30
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