parser

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package parser implements a SQL parser for query validation and parameter extraction.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Parse

func Parse(blk block.Block) (Query, []Diagnostic)

Parse parses a query block into a structured Query object.

Types

type CTE

type CTE struct {
	Name      string
	Columns   []string
	SelectSQL string
	Line      int
	Column    int
}

CTE represents a Common Table Expression.

type Column

type Column struct {
	Expr        string
	Alias       string
	Table       string
	Line        int
	Column      int
	StartOffset int
	EndOffset   int
}

Column represents a result column in a SELECT query.

type Diagnostic

type Diagnostic struct {
	Path      string
	Line      int
	Column    int
	EndColumn int // End column for multi-character spans
	Offset    int // Byte offset in file
	Length    int // Length of the problematic token/region
	Message   string
	Severity  Severity
}

Diagnostic represents an issue found during parsing.

type Param

type Param struct {
	Name          string
	Style         ParamStyle
	Order         int
	Line          int
	Column        int
	IsVariadic    bool
	VariadicCount int
	StartOffset   int
	EndOffset     int
}

Param represents a query parameter.

type ParamStyle

type ParamStyle int

ParamStyle indicates how parameters are specified (positional or named).

const (
	// ParamStyleUnknown indicates an unrecognized parameter style.
	ParamStyleUnknown ParamStyle = iota
	// ParamStylePositional indicates parameters using '?' or '?NNN'.
	ParamStylePositional
	// ParamStyleNamed indicates parameters using ':name'.
	ParamStyleNamed
)

type Query

type Query struct {
	Block       block.Block
	Verb        Verb
	Columns     []Column
	Params      []Param
	CTEs        []CTE
	Diagnostics []Diagnostic
}

Query represents a parsed SQL query with metadata.

type Severity

type Severity int

Severity indicates the seriousness of a diagnostic.

const (
	// SeverityError indicates a fatal parsing error.
	SeverityError Severity = iota
	// SeverityWarning indicates a non-fatal issue.
	SeverityWarning
)

type Verb

type Verb int

Verb indicates the type of SQL statement (SELECT, INSERT, etc.).

const (
	// VerbUnknown indicates an unrecognized statement type.
	VerbUnknown Verb = iota
	// VerbSelect indicates a SELECT statement.
	VerbSelect
	// VerbInsert indicates an INSERT statement.
	VerbInsert
	// VerbUpdate indicates an UPDATE statement.
	VerbUpdate
	// VerbDelete indicates a DELETE statement.
	VerbDelete
)

Jump to

Keyboard shortcuts

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