{"modulePath":"github.com/viant/datly","version":"v1.1.0","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package builder\n\nPackage builder assembles reader SQL from resolved views, selectors, relations, partitions, templates, and dialect capabilities.\n\n## Functions\n\n```go\nfunc MergeViewControlsWithSelector(controls *spec.ViewControls, selector *xstate.Selector) *spec.ViewControls\n```\n\n```go\nfunc MissingPreparedRelationRootSQL(component *spec.Component, relation *data.Relation) error\n```\n\n```go\nfunc NonWindowControls(controls *spec.ViewControls, selector *xstate.Selector) *spec.ViewControls\n```\nNonWindowControls returns the merged controls for the root SQL with the pagination window stripped so derived SQL can safely wrap the full parent query through $View.NonWindowSQL.\n\n```go\nfunc NonWindowSelector(selector *xstate.Selector) *xstate.Selector\n```\n\n```go\nfunc NormalizePreparedRelationSQL(sqlText string) string\n```\n\n```go\nfunc PreparedRelationNonWindowTokens(component *spec.Component) []string\n```\n\n```go\nfunc PreparedRelationSQL(component *spec.Component, relation *data.Relation, rootNonWindowSQL string) (string, error)\n```\nPreparedRelationSQL resolves the authored SQL text for a prepared relation query from the derived runtime relation, including $View.NonWindowSQL expansion. Placeholder binding stays outside this owner: route preparation still binds named placeholders against the already-bound input after this relation-owned SQL text is resolved.\n\n## Types\n\n```go\ntype Builder struct{}\n```\nBuilder assembles reader queries from resolved view, selector, relation, template, partition, and invocation metadata.\n\n```go\nfunc NewBuilder() *Builder\n```\n\n```go\nfunc (b *Builder) Build(ctx context.Context, opts ...BuilderOption) (*cache.ParmetrizedQuery, error)\n```\n\n```go\nfunc (b *Builder) CacheSQL(ctx context.Context, opts ...BuilderOption) (*cache.ParmetrizedQuery, error)\n```\n\n```go\nfunc (b *Builder) ProjectionSource(sqlText string) (string, error)\n```\nProjectionSource prepares relation markers for static projection inspection. The same source owner expands them with invocation values during Build. It neither evaluates input templates nor changes the authored view SQL.\n\n```go\nfunc (b *Builder) QueryMatcher(ctx context.Context, query *cache.ParmetrizedQuery, opts ...BuilderOption) (*cache.ParmetrizedQuery, error)\n```\nQueryMatcher describes relation-local key/window semantics for the exact query executed by the reader. Indexed warmup may use CacheSQL separately; this matcher remains valid for ordinary sqlx lazy-cache replay even when an authored source has no explicit removable parent-key macro.\n\n```go\nfunc (b *Builder) ShapeBound(query *cache.ParmetrizedQuery, opts ...BuilderOption) (*cache.ParmetrizedQuery, error)\n```\nShapeBound applies view selector policy to SQL whose authored placeholders are already bound. It preserves the existing argument order and is used by ordinary output relations that expand parent SQL before selector shaping.\n\n```go\ntype BuilderOption func(*builderOptions)\n```\n\n```go\nfunc WithBuilderBinder(binder xhandler.Binder) BuilderOption\n```\nWithBuilderBinder supplies the invocation-scoped DI binder used by compiled SQL parameter contracts. The builder never retains it beyond Build.\n\n```go\nfunc WithBuilderComponent(component *spec.Component) BuilderOption\n```\n\n```go\nfunc WithBuilderCompositeArgs(columns []string, rows [][]interface{}) BuilderOption\n```\n\n```go\nfunc WithBuilderControls(controls *spec.ViewControls) BuilderOption\n```\n\n```go\nfunc WithBuilderCriteriaCompiler(compiler *criteria.Compiler) BuilderOption\n```\n\n```go\nfunc WithBuilderDialect(dialect *info.Dialect) BuilderOption\n```\n\n```go\nfunc WithBuilderExcludePagination(exclude bool) BuilderOption\n```\n\n```go\nfunc WithBuilderInput(input reflect.Value) BuilderOption\n```\n\n```go\nfunc WithBuilderMatcher(by string, in []any) BuilderOption\n```\n\n```go\nfunc WithBuilderParameterResolver(resolver sqlx.ParameterResolver) BuilderOption\n```\nWithBuilderParameterResolver supplies invocation-scoped named SQL values. SQLX remains the sole owner of placeholder parsing and argument ordering.\n\n```go\nfunc WithBuilderParentQuery(query *cache.ParmetrizedQuery) BuilderOption\n```\nWithBuilderParentQuery supplies the invocation-scoped non-window query exposed through $View.NonWindowSQL in a compiled child-view template.\n\n```go\nfunc WithBuilderParentSelector(selector *xstate.Selector) BuilderOption\n```\nWithBuilderParentSelector supplies parent invocation state that is not part of sqlx's parametrized query, currently the authored page number.\n\n```go\nfunc WithBuilderPartition(partition *PartitionInput) BuilderOption\n```\n\n```go\nfunc WithBuilderPositionalArgs(args []any) BuilderOption\n```\n\n```go\nfunc WithBuilderProjection(columns []string) BuilderOption\n```\n\n```go\nfunc WithBuilderRelation(relation *data.Relation) BuilderOption\n```\n\n```go\nfunc WithBuilderSQL(sqlText string) BuilderOption\n```\n\n```go\nfunc WithBuilderSelector(selector *xstate.Selector) BuilderOption\n```\n\n```go\nfunc WithBuilderSelectorPolicy(policy *spec.Selector) BuilderOption\n```\nWithBuilderSelectorPolicy supplies immutable per-view selector policy. When omitted, the builder derives it from WithBuilderComponent when available.\n\n```go\nfunc WithBuilderSkipRelationFilter(skip bool) BuilderOption\n```\n\n```go\nfunc WithBuilderSource(source *spec.ViewSource) BuilderOption\n```\nWithBuilderSource supplies immutable SQL source metadata as one unit. It is preferred over passing SQL text and controls separately when a view source is available.\n\n```go\nfunc WithBuilderTemplate(evaluator sqltemplate.Evaluator) BuilderOption\n```\nWithBuilderTemplate injects the precompiled root SQL-template evaluator.\n\n```go\nfunc WithBuilderView(view *data.View) BuilderOption\n```\nWithBuilderView supplies the canonical static/runtime-separated view model. SQL construction reads static source/column/selector metadata only.\n\n```go\ntype PartitionInput struct {\n\tTable      string\n\tExpression string\n\tArgs       []any\n}\n```\nPartitionInput is the invocation-local SQL build input produced by a partitioner. Static partitioner identity/concurrency remain view metadata.\n\n```go\nfunc (p *PartitionInput) Clone() *PartitionInput\n```\n\n```go\ntype PreparedRelationBinder struct {\n\tComponent         *spec.Component\n\tRelation          *data.Relation\n\tRootNonWindowSQL  string\n\tRootArgs          []any\n\tParameterResolver sqlx.ParameterResolver\n}\n```\nPreparedRelationBinder owns the route-preparation binding of one prepared relation query. It keeps the relation/query-specific state together so route preparation delegates relation SQL assembly instead of open-coding token scanning and root-arg stitching in the runtime shell.\n\n```go\nfunc (b PreparedRelationBinder) Bind() (string, []any, error)\n```\n\n","path":"github.com/viant/datly/sql/builder","name":"builder","synopsis":"Package builder assembles reader SQL from resolved views, selectors, relations, partitions, templates, and dialect capabilities.","isRedistributable":true}
