Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BindParams ¶
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) Get ¶
func (s *Store) Get(name string) *NamedQuery
Get returns a named query by name, or nil if not found.