Documentation
¶
Overview ¶
Package sql owns stable SQL primitives shared by transcription, compilation, and execution: source resolution, projections, tables, connections, and trace identity. Stateful reader and DML behavior lives in focused subpackages.
Index ¶
- func ApplySelectorProjection(sqlText string, selected []string, view *data.View) (string, error)
- func ContainsAggregate(n node.Node) bool
- func GroupedProjectionCriteriaSource(sqlText string, selected []string) string
- func NormalizeAuthoredSQL(sqlText string) string
- func PrepareExecutableSQL(sqlText string, controls *spec.ViewControls) string
- func ReplaceTable(sqlText, source, target string) (string, error)
- func ResolveSource(viewName string, source *spec.ViewSource, resources fs.FS) error
- func StableTraceID(parts ...string) string
- type CacheProjection
- type Connection
- type Projection
- type ProjectionColumn
- type ProjectionNames
- type SQLComponent
- func (c *SQLComponent) Connector(ctx context.Context, name string) (*sql.DB, error)
- func (c *SQLComponent) Dialect(ctx context.Context) (*info.Dialect, error)
- func (c *SQLComponent) RegisterConnector(name string, db *dsql.DB) error
- func (c *SQLComponent) Resolve(ctx context.Context, connector string) (Connection, error)
- type SelectorProjection
- func (p SelectorProjection) Columns(selected []string) ([]ProjectionColumn, error)
- func (p SelectorProjection) Expand() (string, error)
- func (p SelectorProjection) HasOutput(name string) (found, complete bool, err error)
- func (p SelectorProjection) HasSourceOutput(namespace, name string) (found, complete bool, err error)
- func (p SelectorProjection) LiteralKinds(labels []string) map[int]string
- func (p SelectorProjection) Prepare(selected []string) (*Projection, error)
- func (p SelectorProjection) ResolveDiscoveredColumns(names []string, dialect *info.Dialect) (string, bool, error)
- func (p SelectorProjection) TableColumn(column *data.Column) (*data.Column, error)
- type UnresolvedProjectionError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ApplySelectorProjection ¶
func ContainsAggregate ¶
ContainsAggregate identifies expressions using the same aggregate semantics as grouped projection rewriting.
func GroupedProjectionCriteriaSource ¶
GroupedProjectionCriteriaSource returns the same source scope grouped projection rewriting will use, without changing ordinary full-shape reads.
func NormalizeAuthoredSQL ¶
func PrepareExecutableSQL ¶
func PrepareExecutableSQL(sqlText string, controls *spec.ViewControls) string
func ReplaceTable ¶
ReplaceTable replaces actual table-reference AST nodes, including CTE and union branches. It never performs textual replacement inside expressions, identifiers, literals, or comments.
func ResolveSource ¶
ResolveSource expands the resource references of one cloned SQL view source. Parsing references remains a transcribe/tag concern; this function only materializes the already-typed references into executable SQL.
func StableTraceID ¶
Types ¶
type CacheProjection ¶
CacheProjection supplies native replay metadata from the already-rendered SQL. It reuses the selector grouping owner; it does not authorize columns or change SQL. Opaque outer expressions use declared dimension metadata, or are conservatively dimensions when that authority is absent.
func (CacheProjection) Fields ¶
func (p CacheProjection) Fields() ([]cache.ProjectionField, error)
type Connection ¶
Connection is the DB and dialect pair selected for one view source.
type Projection ¶
type Projection struct {
Source string
// contains filtered or unexported fields
}
Projection keeps source-scope SQL separate from an optional result wrapper. Builders complete predicates/bindings in Source before rendering the result.
func (*Projection) GroupedOutputControls ¶
func (p *Projection) GroupedOutputControls(controls *spec.ViewControls) (*spec.ViewControls, error)
GroupedOutputControls drops inherited ordering that is no longer valid after grouped projection reduction. Explicit selector ordering is validated before controls are merged, so this is only for default/source controls.
func (*Projection) OutputControls ¶
func (p *Projection) OutputControls(controls *spec.ViewControls) (*spec.ViewControls, error)
OutputControls resolves ordering through the actual source/output mapping when a result wrapper changes scope. A matching terminal spelling alone is never enough to authorize another source namespace.
func (*Projection) Render ¶
func (p *Projection) Render(source string) string
type ProjectionColumn ¶
type ProjectionColumn struct {
// contains filtered or unexported fields
}
func (ProjectionColumn) Matches ¶
func (c ProjectionColumn) Matches(name string) bool
func (ProjectionColumn) MatchesOutput ¶
func (c ProjectionColumn) MatchesOutput(name string) bool
func (ProjectionColumn) OrderExpression ¶
func (c ProjectionColumn) OrderExpression() string
func (ProjectionColumn) OutputName ¶
func (c ProjectionColumn) OutputName() string
OutputName is the declared SQL result name, before configured selector aliases.
func (ProjectionColumn) SourceExpression ¶
func (c ProjectionColumn) SourceExpression() string
SourceExpression retains SQL scope when a projected alias is selected away.
type ProjectionNames ¶
type ProjectionNames []string
ProjectionNames contains declared output names and explicit configured aliases. Case-insensitive identifier comparison is shared by fields and order policy. Identifier parts and punctuation remain distinct; alternate spellings need authored SQL aliases or canonical view mappings.
func (ProjectionNames) Matches ¶
func (names ProjectionNames) Matches(name string) bool
type SQLComponent ¶
SQLComponent binds a registered component to its default and named SQL sources. Connector registration is bootstrap state; dialects are resolved lazily and cached with their database handle.
func (*SQLComponent) Connector ¶
Connector is the explicitly opt-in handler provider. Unlike reader Resolve, it never falls back to DB or initializes dialect/transaction state.
func (*SQLComponent) RegisterConnector ¶
func (c *SQLComponent) RegisterConnector(name string, db *dsql.DB) error
RegisterConnector binds an authored connector name to its database handle. Named connectors are bootstrap configuration and must be registered before the component serves requests.
func (*SQLComponent) Resolve ¶
func (c *SQLComponent) Resolve(ctx context.Context, connector string) (Connection, error)
Resolve returns the DB and dialect selected by immutable view connector metadata. A component with no named registrations uses DB as its sole source, including when metadata gives that single source a name.
type SelectorProjection ¶
SelectorProjection owns selector membership in the authored SQL projection. Prepared columns resolve physical wildcard outputs; explicit SQL always wins.
func (SelectorProjection) Columns ¶
func (p SelectorProjection) Columns(selected []string) ([]ProjectionColumn, error)
func (SelectorProjection) Expand ¶
func (p SelectorProjection) Expand() (string, error)
Expand materializes resolved wildcard columns in projection order. The builder uses this for ordering an unnarrowed wildcard, so ordinal policy and executed SQL cannot disagree when prepared column order differs from table order.
func (SelectorProjection) HasOutput ¶
func (p SelectorProjection) HasOutput(name string) (found, complete bool, err error)
HasOutput checks declared SQL output identity. Complete is false only when a physical wildcard or opaque source needs database discovery; invalid SQL and explicit missing outputs are never treated as a wildcard. Prepared Go fields are not evidence that an inner SQL projection exposes a column.
func (SelectorProjection) HasSourceOutput ¶
func (p SelectorProjection) HasSourceOutput(namespace, name string) (found, complete bool, err error)
HasSourceOutput checks a name in the SQL FROM/JOIN scope, rather than in the final SELECT aliases. This prevents a projected selector from claiming an output that its explicitly narrowed derived source does not expose.
func (SelectorProjection) LiteralKinds ¶
func (p SelectorProjection) LiteralKinds(labels []string) map[int]string
LiteralKinds supplies optional defaults for aliased string/integer literals. Result labels and ordinals are database evidence. Parsing failure, CTEs, set sources, and unresolved mappings simply supply no defaults; they never gate an explicit application type. No table schemas or row values are consulted.
func (SelectorProjection) Prepare ¶
func (p SelectorProjection) Prepare(selected []string) (*Projection, error)
Prepare narrows authored outputs before binding while deferring wrappers that hide the source namespace until source predicates have been assembled.
func (SelectorProjection) ResolveDiscoveredColumns ¶
func (p SelectorProjection) ResolveDiscoveredColumns(names []string, dialect *info.Dialect) (string, bool, error)
ResolveDiscoveredColumns materializes an opaque named wildcard from actual database result labels. Only the outer list changes; the inner dialect SQL and all template/binding text remain intact. Prepared Go fields are not input.
func (SelectorProjection) TableColumn ¶
TableColumn keeps physical output names unless the canonical view explicitly declares an alias. Inferred Go field names are mapping destinations, not SQL aliases. Table construction and native matchers consume the same result.
type UnresolvedProjectionError ¶
type UnresolvedProjectionError struct {
Cause error
}
UnresolvedProjectionError means static SQL inspection could not establish a projection. It does not prove a missing output or valid executable SQL. Registration may defer it; selected query construction must still report it.
func (*UnresolvedProjectionError) Error ¶
func (e *UnresolvedProjectionError) Error() string
func (*UnresolvedProjectionError) Unwrap ¶
func (e *UnresolvedProjectionError) Unwrap() error
Source Files
¶
- component.go
- connector.go
- doc.go
- normalize.go
- projection.go
- projection_apply.go
- projection_cache.go
- projection_discovered.go
- projection_error.go
- projection_groupby.go
- projection_item.go
- projection_literal.go
- projection_membership.go
- projection_null.go
- projection_select.go
- projection_set.go
- projection_wildcard.go
- source.go
- table.go
- trace_id.go
- view_controls.go
Directories
¶
| Path | Synopsis |
|---|---|
|
Package builder assembles reader SQL from resolved views, selectors, relations, partitions, templates, and dialect capabilities.
|
Package builder assembles reader SQL from resolved views, selectors, relations, partitions, templates, and dialect capabilities. |
|
Package criteria validates client predicates using the SQL parser's AST and emits only approved columns, operators, and bound values.
|
Package criteria validates client predicates using the SQL parser's AST and emits only approved columns, operators, and bound values. |
|
Package dml provides the SQLX-backed buffered write and transaction scope.
|
Package dml provides the SQLX-backed buffered write and transaction scope. |
|
Package fragment owns authored SQL predicate fragments and their ordered invocation bindings.
|
Package fragment owns authored SQL predicate fragments and their ordered invocation bindings. |
|
Package macro parses and expands Datly SQL macros such as ParentJoinOn, ParentKey, and parent NonWindowSQL access.
|
Package macro parses and expands Datly SQL macros such as ParentJoinOn, ParentKey, and parent NonWindowSQL access. |
|
Package reader owns immutable SQL read plans and SQLX-backed execution with fresh invocation sessions, typed rows, relations, partitions, hooks, and the native SQLX cache path.
|
Package reader owns immutable SQL read plans and SQLX-backed execution with fresh invocation sessions, typed rows, relations, partitions, hooks, and the native SQLX cache path. |
|
collector
Package collector owns reader-compiled relation graphs and typed row assembly.
|
Package collector owns reader-compiled relation graphs and typed row assembly. |
|
compiler
Package compiler converts canonical view metadata and typed contracts into immutable SQL reader plans.
|
Package compiler converts canonical view metadata and typed contracts into immutable SQL reader plans. |
|
provider
Package provider adapts SQL reader dependencies to Bindly providers.
|
Package provider adapts SQL reader dependencies to Bindly providers. |
|
readmeta
Package readmeta carries immutable evidence from actual typed SQL reads.
|
Package readmeta carries immutable evidence from actual typed SQL reads. |
|
rowcodec
Package rowcodec compiles column codecs into typed SQLX scan wrappers.
|
Package rowcodec compiles column codecs into typed SQLX scan wrappers. |
|
Package sequencer provides SQLX-backed identifier allocation.
|
Package sequencer provides SQLX-backed identifier allocation. |
|
Package template owns compiled SQL-template programs.
|
Package template owns compiled SQL-template programs. |
|
Package validation combines native Go and SQL constraint checks for one invocation-scoped typed entity.
|
Package validation combines native Go and SQL constraint checks for one invocation-scoped typed entity. |