pipes

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BindParams

func BindParams(q *NamedQuery, supplied map[string]any) (string, []any, error)

BindParams replaces {{param}} and {{param:default}} placeholders in a NamedQuery's SQL with supplied values or defaults. Formally declared Parameters provide type info and required/default metadata. Inline {{name:default}} syntax also works without formal parameter definitions.

Values are inlined directly into the SQL string (scalars are escaped, arrays render as a parenthesized list — see formatParamValue). This avoids driver-level positional parameter limitations (e.g. LIMIT position).

Types

type NamedQuery

type NamedQuery struct {
	Name         string     `json:"name"`
	SQL          string     `json:"sql"`
	Parameters   []ParamDef `json:"parameters,omitempty"`
	Description  string     `json:"description,omitempty"`
	AllowedRoles []string   `json:"allowed_roles,omitempty"` // empty = admin role only (fails closed)
}

NamedQuery is a pre-defined SQL template with parameter support.

type ParamDef

type ParamDef struct {
	Name string `json:"name"`
	// Type documents the expected value kind ("string", "number", "boolean",
	// "array") for callers and the SDK. It is advisory only — binding keys off
	// the runtime value, and ClickHouse validates against the column type.
	Type     string `json:"type"`
	Required bool   `json:"required,omitempty"`
	Default  any    `json:"default,omitempty"`
}

ParamDef describes a query parameter.

type Source added in v0.2.0

type Source interface {
	// Pipe returns the named query, or nil when none is defined.
	Pipe(name string) *NamedQuery
	// Pipes returns every named query.
	Pipes() []*NamedQuery
}

Source yields the named queries a request may run, read per call so a settings-directory reload applies to the next request. In production the Source is settings.Store (pipes.json); Static serves tests.

func Static added in v0.2.0

func Static(queries ...*NamedQuery) Source

Static returns a fixed in-memory Source. Intended for tests.

Jump to

Keyboard shortcuts

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