Documentation
¶
Overview ¶
Package codegen renders a relalg.Expr (logical plan) into dialect-specific, fully parameterized SQL. User values always bind to placeholders — never string-interpolated — so generated SQL is inject-proof (invariant I3).
A Renderer holds a dialect.Dialect. Compile produces a Compiled value carrying the SQL, args, read-only flag, affected tables, and (when the caller supplies primary-key columns via WithPrimaryKey) an IsPKPoint flag for the cost gate's whitelist.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrUnsupportedExpr = errors.New("codegen: unsupported expression")
ErrUnsupportedExpr is returned when the renderer encounters an expression it cannot render.
Functions ¶
This section is empty.
Types ¶
type CompileOption ¶
type CompileOption func(*compileConfig)
CompileOption configures Compile.
func WithMaxINCardinality ¶
func WithMaxINCardinality(max int) CompileOption
WithMaxINCardinality sets the maximum accepted IN/NOT IN list size. Values must be positive; invalid values fail compilation rather than disabling the bound.
func WithPrimaryKey ¶
func WithPrimaryKey(cols ...string) CompileOption
WithPrimaryKey supplies primary-key columns so Compile can detect a primary key point lookup and set Compiled.IsPKPoint.
type Compiled ¶
type Compiled struct {
Expr relalg.Expr
Kind Kind
SQL string
Args []any
IsPKPoint bool // all primary-key columns matched by equality (gate whitelist)
PrimaryKey []string // primary-key columns, when supplied via WithPrimaryKey
ReadOnly bool
AffectedTables []string // tables touched by a write (cache invalidation)
}
Compiled is the physical, executable product of a logical plan: the rendered SQL, bound args, and metadata consumed by the cost gate, cache, and store.
type Renderer ¶
Renderer renders relalg expressions for a single dialect.
func NewRenderer ¶
NewRenderer returns a Renderer for the given dialect.
func (Renderer) Compile ¶
Compile renders e into a Compiled value. It applies inline lightweight transforms (IsPKPoint detection) and capability-driven rendering (e.g. RETURNING). It does not run a separate optimizer: the IR is deliberately limited (no join/subquery), so predicate pushdown has nothing to push over.