Documentation
¶
Overview ¶
Package codegen emits the generated Go package: fragment tables, typed params/row structs, and one function per query. See docs/design/06-codegen-runtime.md.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BuildFrags ¶
func BuildFrags(profile dialect.LexerProfile, q *template.QueryTemplate) []runtime.Frag
BuildFrags lowers a scanned template into the runtime fragment table. Parameter tokens are located at generate time (via the same lexer profile as everything else) so runtime composition never scans SQL. Param indices refer to positions in q.ParamOrder.
The conformance test asserts that runtime.Compose over this table is byte-identical to ast.RenderShape for every enumerable shape — the implementation of "what is verified is byte-wise what is composed".
func Generate ¶
func Generate(opts Options, tm dialect.TypeMap, queries []QueryInput) (map[string][]byte, []diagnostics.Diagnostic)
Generate emits the full package: db.gen.go, querier.gen.go, and one <query>.sql.gen.go per query — every emitted name ends in ".gen.go" so generated files are recognizable by name, not only by the "Code generated" header. Returns file contents keyed by base name; any diagnostics mean the emission is incomplete and must not be written.
Types ¶
type Options ¶
type Options struct {
Package string
// TreeCaps bounds @filter-tree values; zero fields fall back to
// runtime.DefaultTreeCaps.
TreeCaps runtime.TreeCaps
// Style is the dialect's placeholder style; it selects the driver
// flavor of the generated code (StyleDollar → pgx, StyleQuestion →
// database/sql) and the composition entry points.
Style runtime.Style
// DefaultTimeout is query_timeout.default (design 23): the deadline
// of every method whose query has no `-- @timeout`. 0 = none.
DefaultTimeout time.Duration
// Explain selects the EXPLAIN vocabulary of the generated
// Explain<Query> methods (design 22). Zero means "derive from
// Style", which is only unambiguous for StyleDollar (PostgreSQL):
// MySQL and SQLite share StyleQuestion, so they must say which.
Explain runtime.ExplainDialect
}
type QueryInput ¶
type QueryInput struct {
Q *template.QueryTemplate
Frags []runtime.Frag
ParamTypes map[string]dialect.TypeRef // pinned types (premise P1)
Columns []dialect.ColumnDesc // maximal Describe result
Nullable []bool // per column (P5)
// NullableParams holds the parameters rules.DeriveNullableParams
// found writing only nullable columns (design 20 §3): their values
// become optional.Option[T], None binding SQL NULL.
NullableParams map[string]bool
// ExpandedShapes, when non-nil, switches the query to strict static
// expansion: keys are canonical shape-key strings, precomputed by
// the pipeline via runtime.Compose. The function dispatches by
// lookup instead of composing.
ExpandedShapes map[string]runtime.Expanded
}
QueryInput is everything codegen needs for one query, produced by the earlier pipeline phases.