dql

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2026 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Overview

Package dql implements focused DQL syntax parsing for the transcribe pipeline. Production callers enter through transcribe.Compiler rather than composing these parsers directly.

Index

Constants

View Source
const (
	DiagnosticInvalidPackage = "DQL-DIR-PACKAGE"
	DiagnosticInvalidImport  = "DQL-DIR-IMPORT"
	DiagnosticInvalidSetting = "DQL-DIR-SETTING"
	DiagnosticInvalidDefine  = "DQL-DIR-DEFINE"
	DiagnosticParse          = "DQL-PARSE"
)

Variables

View Source
var ErrMissingRouteDirective = errors.New("missing #setting route directive in source")

ErrMissingRouteDirective reports a source with no #setting route directive: valid SQL, but not a component source. Callers that scan mixed SQL assets (e.g. transcribe source discovery) classify non-component files with errors.Is against this sentinel instead of re-implementing detection.

Functions

func ApplyPatch

func ApplyPatch(source string, span SourceSpan, replacement string) (string, error)

ApplyPatch applies one half-open byte patch to authored DQL.

func ColumnType

func ColumnType(expression string, context *spec.TypeContext) (spec.TypeRef, error)

ColumnType normalizes authored column type declarations under the component's import authority. Fluent ColumnType and projection CAST share this policy.

func EmbeddedSQLRefs

func EmbeddedSQLRefs(sql string) []*spec.EmbeddedSQLRef

EmbeddedSQLRefs extracts typed resource references from one authored SQL source. Resource expansion remains a later transcribe load concern.

func ParsePreparedComponentSource

func ParsePreparedComponentSource(scope, name string, prepared *PreparedSource) (*spec.Component, error)

func RenderPredicateOption

func RenderPredicateOption(predicate *spec.Predicate) (string, error)

RenderPredicateOption renders the canonical declaration option spelling.

func SetPackage

func SetPackage(source, packagePath, expected string) (string, error)

SetPackage replaces the one authored package directive while preserving all surrounding source bytes. Expected enables revision-aware callers to verify that package authority has not changed since inspection.

func UpsertSetting

func UpsertSetting(source, name string, args []string) (string, error)

UpsertSetting replaces every authored setting call with the same canonical name by one call at the first occurrence, or inserts a new call before SQL. A nil args slice removes the setting. Arguments are already-authored DQL expressions and are retained verbatim after trimming.

func UpsertSettingTail

func UpsertSettingTail(source, name string, args []string, tail string) (string, error)

Types

type DeclarationAnalysis

type DeclarationAnalysis struct {
	SQL                       string
	FromPath                  string
	Table                     string
	Projection                []DeclarationProjection
	ProjectionComplete        bool
	DeclarationCriteriaIn     *DeclarationCriteriaIn
	DeclarationScalarProperty *DeclarationScalarProperty
	DataType                  string
}

func AnalyzeDeclarationSQL

func AnalyzeDeclarationSQL(raw string) (*DeclarationAnalysis, error)

func (*DeclarationAnalysis) NestedChildField

func (a *DeclarationAnalysis) NestedChildField() string

type DeclarationCriteriaIn

type DeclarationCriteriaIn struct {
	Column      string
	HelperField string
}

type DeclarationOccurrence

type DeclarationOccurrence struct {
	Parameter    *spec.Parameter               `json:"parameter"`
	Span         SourceSpan                    `json:"span"`
	HeadSpan     SourceSpan                    `json:"headSpan"`
	OptionInsert int                           `json:"optionInsert"`
	Options      []DeclarationOptionOccurrence `json:"options,omitempty"`
	Predicates   []PredicateOptionOccurrence   `json:"predicates,omitempty"`
}

DeclarationOccurrence retains one authored declaration and the source ranges needed by source-preserving editor clients. Parameter is detached metadata; Span and predicate spans address the complete authored DQL.

func DeclarationOccurrences

func DeclarationOccurrences(source string) ([]DeclarationOccurrence, error)

DeclarationOccurrences parses every authored parameter declaration without applying #define-over-#set precedence. This is an authoring projection; the canonical component continues to use the normalized declaration plan.

type DeclarationOptionOccurrence

type DeclarationOptionOccurrence struct {
	Name string     `json:"name"`
	Args []string   `json:"args,omitempty"`
	Span SourceSpan `json:"span"`
}

type DeclarationProjection

type DeclarationProjection struct {
	Name      string
	Source    string
	Aggregate bool
}

DeclarationProjection is one parser-proven StructQL destination field. Name is the result alias (or source name when no alias was authored), while Source is the selected source field used to derive its concrete Go type.

type DeclarationScalarProperty

type DeclarationScalarProperty struct {
	Column      string
	SourceField string
	Property    string
}

type DirectivePlan

type DirectivePlan struct {
	Static        *spec.StaticContent
	Documentation xdocs.Source
	Route         *RoutePlan
	Settings      *spec.Settings
	MCP           *spec.MCPExposure
	MCPOnly       bool
	Params        []*spec.Parameter
	Views         []*spec.View
	ParamSpans    map[string]SourceSpan
	ConstSpans    map[string]SourceSpan
	// contains filtered or unexported fields
}

DirectivePlan is the normalized canonical product of one authored directive scan. Component assembly consumes this plan and never rescans the original source for routes, settings, or declarations.

type PredicateOptionOccurrence

type PredicateOptionOccurrence struct {
	Ordinal   int             `json:"ordinal"`
	Predicate *spec.Predicate `json:"predicate"`
	Span      SourceSpan      `json:"span"`
}

PredicateOptionOccurrence identifies one repeatable predicate option in its declaration. Ordinal is scoped to the declaration and follows source order.

type PreparedSource

type PreparedSource struct {
	Original    string
	DirectSQL   string
	SQL         string
	TrimPrefix  int
	TypeContext *spec.TypeContext
	Directives  *DirectivePlan
	Statements  statement.Statements
	Diagnostics []SourceDiagnostic
}

PreparedSource is the offset-preserving output of authored DQL preprocessing. Directives carries canonical route/settings/parameter data; SQL contains only executable source and Original is retained for diagnostics.

func PrepareSource

func PrepareSource(source string) *PreparedSource

PrepareSource ports the original directive-masking preprocess stage using the shared parser-backed directive scanner. Masking preserves authored byte offsets and line endings; only outer SQL whitespace is trimmed.

func (*PreparedSource) Err

func (p *PreparedSource) Err() error

type RoutePlan

type RoutePlan struct {
	URI          string
	Methods      []string
	APIKeyHeader string
	APIKeyValue  string
}

type Serializer

type Serializer struct{}

func (Serializer) Export

func (Serializer) Export(component *spec.Component, authored string) SourceExport

type SourceDiagnostic

type SourceDiagnostic struct {
	Code    string
	Message string
	Offset  int
	End     int
}

func DiagnosticForError

func DiagnosticForError(err error) (SourceDiagnostic, bool)

DiagnosticForError extracts an authored-source diagnostic from a DQL parse error when the focused parser knows the failing directive span.

type SourceExport

type SourceExport struct {
	Source      string   `json:"source"`
	Original    bool     `json:"original"`
	Supported   bool     `json:"supported"`
	Limitations []string `json:"limitations"`
}

SourceExport separates retained authorship from bounded reconstruction.

type SourceSpan

type SourceSpan struct {
	Start int `json:"start"`
	End   int `json:"end"`
}

type TemplateExpressions

type TemplateExpressions struct{}

TemplateExpressions hands template operands to Velty while SQLParser owns the surrounding SQL. Raw nodes retain the authored bytes for later execution.

func (TemplateExpressions) Parse

func (TemplateExpressions) Parse(err error, cursor *parsly.Cursor, destination any) error

Directories

Path Synopsis
Package statement segments preprocessed DQL into top-level SQL and Velty operations.
Package statement segments preprocessed DQL into top-level SQL and Velty operations.

Jump to

Keyboard shortcuts

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