Skip to main content

Module query

Module query 

Expand description

query IR — the declarative, parameterized custom-SQL read block (cratestack#867; accepted design docs/design/declarative-custom-query.md, adopted by epic cratestack#488’s 2026-09-02 decision comment).

A query is deliberately not a procedure with a body and not a parameterized view:

  • Unlike Procedure, it carries a SQL body and is never public wire surface — no REST route, no RPC op id, no generated client stub. That is why it is a separate list on Schema rather than a new Procedure field: every route/op/client emission site iterates procedures and models, so a construct they never loop over costs nothing, whereas a flag on Procedure would need an “is this one internal” branch at five sites (design §1).
  • Unlike View, it emits no DDL and creates no persistent database object, and its SQL takes runtime bind parameters — which CREATE VIEW has no slot for at all.

The arg list reuses ProcedureArg verbatim rather than defining a near-identical twin: the policy resolver (cratestack-macros/src/policy/procedure/resolver.rs) resolves @allow/@deny predicates purely against an arg list and the schema’s type declarations, with no model dependency, so sharing the type is what lets a query reuse it with no new machinery (design §6).

Modules§

placeholders
Positional-placeholder scan over a query block’s raw SQL body.

Structs§

Query

Constants§

QUERY_SQL_ATTRIBUTE
The attribute a query block’s SQL body is written in.

Functions§

scan_sql_placeholders
Every distinct N in a $N token appearing in sql as an actual parameter reference, ascending.