pipes

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2026 License: Apache-2.0 Imports: 12 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 Store

type Store struct {
	// contains filtered or unexported fields
}

Store manages named query persistence via NATS KV with optional file bootstrap.

func NewMemoryStore

func NewMemoryStore(queries ...*NamedQuery) *Store

NewMemoryStore creates an in-memory pipes store for testing without NATS.

func NewStore

func NewStore(ctx context.Context, js jetstream.JetStream, directory string, logger *slog.Logger) (*Store, error)

NewStore creates a pipes store backed by NATS KV. If directory is non-empty, .sql files in it are loaded on startup.

func (*Store) Delete

func (s *Store) Delete(ctx context.Context, name string) error

Delete removes a named query from the store.

func (*Store) Get

func (s *Store) Get(name string) *NamedQuery

Get returns a named query by name, or nil if not found.

func (*Store) List

func (s *Store) List() []*NamedQuery

List returns all cached named queries.

func (*Store) Put

func (s *Store) Put(ctx context.Context, q *NamedQuery) error

Put saves a named query to the NATS KV store.

Jump to

Keyboard shortcuts

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