codegen

package
v0.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 11, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

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.

func GoName

func GoName(name string) string

GoName maps a snake_case (or arbitrary SQL) identifier to an exported Go name. Collisions after mapping are the caller's job to detect (SQLETCH310) — this function never disambiguates silently.

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
}

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)
	// 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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL