template

package
v1.1.0 Latest Latest
Warning

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

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

Documentation

Overview

Package template owns compiled SQL-template programs. It evaluates authored SQL control flow before sql/builder applies projection, criteria, relations, pagination, partitioning, and placeholder binding.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Compiler

type Compiler struct {
	// Const is immutable trusted deployment data, never invocation input.
	Const            *constant.Values
	Source           string
	InputType        reflect.Type
	Variables        []Variable
	NonWindowAliases []string
	Predicate        dexec.PredicateEvaluator
}

Compiler compiles one SQL source against its canonical input type.

func (Compiler) Compile

func (c Compiler) Compile() (Evaluator, error)

Compile returns nil for plain SQL and a reusable evaluator when the parsed source contains executable Velty control flow or SQL context calls.

type ConstantRenderer

type ConstantRenderer struct {
	Values    *constant.Values
	Variables []string
}

ConstantRenderer uses Velty's emitted-expression spans and SQLParser's quote boundaries. Template decisions, calls, locals and SQL string/comment data are not constant identifier sites. A qualified emitted reference rooted in a declared scalar constant is an identifier; ordinary scalar emission stays bound.

func (ConstantRenderer) Identifier

func (r ConstantRenderer) Identifier(table string) (string, error)

Identifier renders transient table metadata through the SQL rendering owner.

func (ConstantRenderer) Validate

func (r ConstantRenderer) Validate(source string) error

Validate checks identifier values and native source spans without expanding SQL.

type Evaluator

type Evaluator interface {
	Evaluate(context.Context, Invocation) (Result, error)
}

Evaluator is the injected SQL-template execution boundary.

type Invocation

type Invocation struct {
	Input  reflect.Value
	View   ViewInput
	Binder xhandler.Binder
}

Invocation contains the canonical bound input for one template evaluation.

type Result

type Result struct {
	SQL  string
	Args []any
	// ParentBindings reports that $View rendered or excluded a parent-key
	// helper, so the builder must not run a second relation-binding path.
	ParentBindings bool
}

Result is the expanded authored SQL handed back to the SQL builder.

type Variable

type Variable struct {
	Name       string
	FieldIndex []int
	Type       reflect.Type
	Key        xhandler.ValueKey
	Required   bool
}

Variable maps an authored DQL parameter name to one typed input field.

type ViewInput

type ViewInput struct {
	Dialect               *info.Dialect
	ParentValues          []any
	ParentCompositeValues [][]interface{}
	ExcludeParent         bool
	Limit                 int
	Offset                int
	Page                  int
	NonWindowSQL          string
	NonWindowArgs         []any
}

ViewInput contains invocation-scoped values exposed through $View.

Jump to

Keyboard shortcuts

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