codegen

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2026 License: MIT Imports: 6 Imported by: 0

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

View Source
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)
	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 Kind

type Kind string

Kind identifies the execution class of a compiled statement.

const (
	KindRead      Kind = "read"
	KindAggregate Kind = "aggregate"
	KindWrite     Kind = "write"
	KindCall      Kind = "call"
)

type Renderer

type Renderer struct {
	Dialect dialect.Dialect
}

Renderer renders relalg expressions for a single dialect.

func NewRenderer

func NewRenderer(d dialect.Dialect) Renderer

NewRenderer returns a Renderer for the given dialect.

func (Renderer) Compile

func (r Renderer) Compile(e relalg.Expr, opts ...CompileOption) (Compiled, error)

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.

Jump to

Keyboard shortcuts

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