{"modulePath":"github.com/viant/datly","version":"v1.1.0","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package sql\n\nPackage 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.\n\n## Functions\n\n```go\nfunc ApplySelectorProjection(sqlText string, selected []string, view *data.View) (string, error)\n```\n\n```go\nfunc ContainsAggregate(n node.Node) bool\n```\nContainsAggregate identifies expressions using the same aggregate semantics as grouped projection rewriting.\n\n```go\nfunc GroupedProjectionCriteriaSource(sqlText string, selected []string) string\n```\nGroupedProjectionCriteriaSource returns the same source scope grouped projection rewriting will use, without changing ordinary full-shape reads.\n\n```go\nfunc NormalizeAuthoredSQL(sqlText string) string\n```\n\n```go\nfunc PrepareExecutableSQL(sqlText string, controls *spec.ViewControls) string\n```\n\n```go\nfunc ReplaceTable(sqlText, source, target string) (string, error)\n```\nReplaceTable replaces actual table-reference AST nodes, including CTE and union branches. It never performs textual replacement inside expressions, identifiers, literals, or comments.\n\n```go\nfunc ResolveSource(viewName string, source *spec.ViewSource, resources fs.FS) error\n```\nResolveSource 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.\n\n```go\nfunc StableTraceID(parts ...string) string\n```\n\n## Types\n\n```go\ntype CacheProjection struct {\n\tSQL  string\n\tView *data.View\n}\n```\nCacheProjection 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.\n\n```go\nfunc (p CacheProjection) Fields() ([]cache.ProjectionField, error)\n```\n\n```go\ntype Connection struct {\n\tDB      *dsql.DB\n\tTx      *dsql.Tx\n\tDialect *info.Dialect\n}\n```\nConnection is the DB and dialect pair selected for one view source.\n\n```go\ntype Projection struct {\n\tSource string\n\t// contains filtered or unexported fields\n}\n```\nProjection keeps source-scope SQL separate from an optional result wrapper. Builders complete predicates/bindings in Source before rendering the result.\n\n```go\nfunc (p *Projection) GroupedOutputControls(controls *spec.ViewControls) (*spec.ViewControls, error)\n```\nGroupedOutputControls 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.\n\n```go\nfunc (p *Projection) OutputControls(controls *spec.ViewControls) (*spec.ViewControls, error)\n```\nOutputControls 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.\n\n```go\nfunc (p *Projection) Render(source string) string\n```\n\n```go\ntype ProjectionColumn struct {\n\t// contains filtered or unexported fields\n}\n```\n\n```go\nfunc (c ProjectionColumn) Matches(name string) bool\n```\n\n```go\nfunc (c ProjectionColumn) MatchesOutput(name string) bool\n```\n\n```go\nfunc (c ProjectionColumn) OrderExpression() string\n```\n\n```go\nfunc (c ProjectionColumn) OutputName() string\n```\nOutputName is the declared SQL result name, before configured selector aliases.\n\n```go\nfunc (c ProjectionColumn) SourceExpression() string\n```\nSourceExpression retains SQL scope when a projected alias is selected away.\n\n```go\ntype ProjectionNames []string\n```\nProjectionNames 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.\n\n```go\nfunc (names ProjectionNames) Matches(name string) bool\n```\n\n```go\ntype SQLComponent struct {\n\tDB *dsql.DB\n\t// Tx is a caller-owned transaction for reader execution against DB.\n\t// Named connectors must resolve to the same DB while Tx is set.\n\tTx *dsql.Tx\n\t// contains filtered or unexported fields\n}\n```\nSQLComponent 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.\n\n```go\nfunc (c *SQLComponent) Connector(ctx context.Context, name string) (*sql.DB, error)\n```\nConnector is the explicitly opt-in handler provider. Unlike reader Resolve, it never falls back to DB or initializes dialect/transaction state.\n\n```go\nfunc (c *SQLComponent) ConnectorDataSource(ctx context.Context, name string) (dexec.DataSource, error)\n```\nConnectorDataSource adapts a registered connector to the neutral execution port without opening a transaction or transferring database ownership.\n\n```go\nfunc (c *SQLComponent) Dialect(ctx context.Context) (*info.Dialect, error)\n```\n\n```go\nfunc (c *SQLComponent) RegisterConnector(name string, db *dsql.DB) error\n```\nRegisterConnector binds an authored connector name to its database handle. Named connectors are bootstrap configuration and must be registered before the component serves requests.\n\n```go\nfunc (c *SQLComponent) Resolve(ctx context.Context, connector string) (Connection, error)\n```\nResolve 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.\n\n```go\ntype SelectorProjection struct {\n\tSQL  string\n\tView *data.View\n}\n```\nSelectorProjection owns selector membership in the authored SQL projection. Prepared columns resolve physical wildcard outputs; explicit SQL always wins.\n\n```go\nfunc (p SelectorProjection) Columns(selected []string) ([]ProjectionColumn, error)\n```\n\n```go\nfunc (p SelectorProjection) Expand() (string, error)\n```\nExpand 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.\n\n```go\nfunc (p SelectorProjection) HasOutput(name string) (found, complete bool, err error)\n```\nHasOutput 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.\n\n```go\nfunc (p SelectorProjection) HasSourceOutput(namespace, name string) (found, complete bool, err error)\n```\nHasSourceOutput 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.\n\n```go\nfunc (p SelectorProjection) LiteralKinds(labels []string) map[int]string\n```\nLiteralKinds 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.\n\n```go\nfunc (p SelectorProjection) Prepare(selected []string) (*Projection, error)\n```\nPrepare narrows authored outputs before binding while deferring wrappers that hide the source namespace until source predicates have been assembled.\n\n```go\nfunc (p SelectorProjection) ResolveDiscoveredColumns(names []string, dialect *info.Dialect) (string, bool, error)\n```\nResolveDiscoveredColumns 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.\n\n```go\nfunc (p SelectorProjection) TableColumn(column *data.Column) (*data.Column, error)\n```\nTableColumn 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.\n\n```go\ntype UnresolvedProjectionError struct {\n\tCause error\n}\n```\nUnresolvedProjectionError 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.\n\n```go\nfunc (e *UnresolvedProjectionError) Error() string\n```\n\n```go\nfunc (e *UnresolvedProjectionError) Unwrap() error\n```\n\n","path":"github.com/viant/datly/sql","name":"sql","synopsis":"Package sql owns stable SQL primitives shared by transcription, compilation, and execution: source resolution, projections, tables, connections, and trace identity.","isRedistributable":true}
