sqlparser

package module
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2026 License: Apache-2.0 Imports: 21 Imported by: 19

README

sqlparser

SQL Parser

Documentation

Index

Constants

View Source
const (
	KindUnknown       = "unknown"
	KindSelect        = "select"
	KindLoad          = "load"
	KindInsert        = "insert"
	KindUpdate        = "update"
	KindMerge         = "merge"
	KindDelete        = "delete"
	KindRegisterType  = "register type"
	KindRegisterSet   = "register set"
	KindCreateTable   = "create table"
	KindDropTable     = "drop table"
	KindCreateIndex   = "create index"
	KindDropIndex     = "drop index"
	KindTruncateTable = "truncate table"
)

Variables

This section is empty.

Functions

func Parse

func Parse(cursor *parsly.Cursor, dest interface{}) error

Parse parses SQL into supplied destination

func ParseCallExpr

func ParseCallExpr(rawExpr string) (*expr.Call, error)

ParseCallExpr parses call expression

func ParseCreateIndex added in v0.7.1

func ParseCreateIndex(SQL string) (*index.Create, error)

ParseCreateIndex parses create table

func ParseCreateTable

func ParseCreateTable(SQL string) (*table.Create, error)

ParseCreateTable parses create table

func ParseDelete

func ParseDelete(SQL string) (*del.Statement, error)

ParseDelete parses DELETE statement

func ParseDropIndex added in v0.7.1

func ParseDropIndex(SQL string) (*index.Drop, error)

ParseDropIndex parses drop table

func ParseDropTable

func ParseDropTable(SQL string) (*table.Drop, error)

ParseDropTable parses drop table

func ParseInsert

func ParseInsert(SQL string) (*insert.Statement, error)

ParseInsert Parses INSERT INTO statement

func ParseList

func ParseList(raw string) (query.List, error)

ParseList parses list

func ParseLiteral

func ParseLiteral(cursor *parsly.Cursor) (*expr.Literal, error)

ParseLiteral parses literal

func ParseQualify

func ParseQualify(cursor *parsly.Cursor, qualify *expr.Qualify) error

ParseQualify parses qualify expr

func ParseQuery

func ParseQuery(SQL string, opts ...Option) (*query.Select, error)

ParseQuery parses query

func ParseRegisterSet added in v0.7.0

func ParseRegisterSet(SQL string) (*schema.RegisterSet, error)

ParseRegisterSet parses register set

func ParseRegisterType added in v0.6.0

func ParseRegisterType(SQL string) (*schema.Register, error)

ParseRegisterType parses register type

func ParseTruncateTable added in v0.7.1

func ParseTruncateTable(SQL string) (*table.Truncate, error)

ParseTruncateTable parses truncate table

func ParseUpdate

func ParseUpdate(SQL string) (*update.Statement, error)

ParseUpdate parses update statement

func SourceTable added in v0.13.0

func SourceTable(value node.Node) (table string, parenthesized bool, err error)

SourceTable identifies one complete table reference and whether parentheses enclose it. Subqueries and other source expressions return an empty name. It uses the SQL table/parenthesis token owners, never keyword text heuristics, and does not mutate the supplied AST (including partially populated Raw.X).

func Stringify

func Stringify(n node.Node) string

Stringify retains the established SQL rendering contract.

func StripCollate added in v0.11.0

func StripCollate(SQL string) (string, error)

StripCollate removes COLLATE expressions from SQL while preserving structure.

func TableIdentifierParts added in v0.13.0

func TableIdentifierParts(source string) ([]string, error)

TableIdentifierParts parses one complete qualified table identifier into decoded name parts. It does not split dots inside delimited identifiers or accept aliases, expressions, placeholders or trailing SQL. Delimiters follow SQL doubled-quote rules (including backticks/brackets used by SQL dialects). TableName/TableSelector retain their existing AST/string behavior.

func TableName

func TableName(node node.Node) string

TableName returns main table name

func TableSelector added in v0.8.1

func TableSelector(n node.Node) *expr.Selector

TableSelector returns the table selector Node

func Traverse added in v0.4.0

func Traverse(n node.Node, visitor func(n node.Node) bool)

Traverse traverse node

func TryParseLiteral

func TryParseLiteral(cursor *parsly.Cursor) (*expr.Literal, error)

TryParseLiteral tries to parse literal

Types

type Cast added in v0.13.0

type Cast struct {
	Operand string
	Type    string
}

Cast describes a CAST operand and its authored type without interpreting the type as either a SQL dialect type or a host-language type.

func CastExpression added in v0.13.0

func CastExpression(call *expr.Call) (*Cast, error)

CastExpression returns nil for another function. It retains custom type spelling rather than applying NewColumn's legacy SQL type approximation. Both CAST(value AS type) and the declaration-compatible CAST(value,'type') form are accepted; consumers decide whether a call is executable or metadata.

type Column added in v0.4.0

type Column column.Spec

Column represent column

func NewColumn added in v0.4.0

func NewColumn(item *query.Item) *Column

func (*Column) Identity added in v0.5.1

func (c *Column) Identity() string

type ColumnLineage added in v0.13.0

type ColumnLineage struct {
	// contains filtered or unexported fields
}

ColumnLineage is immutable compiled projection provenance. Lookup handles proven wildcard sources without changing or walking an execution row type.

func (*ColumnLineage) Lookup added in v0.13.0

func (c *ColumnLineage) Lookup(name string) (ColumnOrigin, bool)

func (*ColumnLineage) RootTable added in v0.13.0

func (c *ColumnLineage) RootTable() string

type ColumnOrigin added in v0.13.0

type ColumnOrigin struct{ Table, Column string }

ColumnOrigin is parser-proven direct table/column provenance.

type Columns added in v0.4.0

type Columns []*Column

Columns represens column

func NewColumns added in v0.4.0

func NewColumns(list query.List) Columns

NewColumns creates a columns

func (Columns) ByLowerCase added in v0.5.1

func (c Columns) ByLowerCase() map[string]*Column

ByLowerCase indexes column by lower cased name

func (Columns) ByName added in v0.4.0

func (c Columns) ByName() map[string]*Column

ByName indexes column by name

func (Columns) Index added in v0.4.0

func (c Columns) Index() map[string]*Column

Index indexes column by first non-empty alias or name or expr respectively

func (Columns) IsStarExpr added in v0.4.0

func (c Columns) IsStarExpr() bool

func (Columns) Namespace added in v0.4.0

func (c Columns) Namespace(namespace string) Columns

Namespace returns namespace column

func (Columns) StarExpr added in v0.4.0

func (c Columns) StarExpr(namespace string) *Column

StarExpr returns star expr

type Kind added in v0.6.0

type Kind string

Kind represents the type of SQL statement.

func ParseKind added in v0.6.0

func ParseKind(SQL string) Kind

func (Kind) IsCreateTable added in v0.6.0

func (k Kind) IsCreateTable() bool

IsCreateTable returns true if the Kind is KindCreateTable.

func (Kind) IsDelete added in v0.6.0

func (k Kind) IsDelete() bool

IsDelete returns true if the Kind is KindDelete.

func (Kind) IsDropTable added in v0.6.0

func (k Kind) IsDropTable() bool

IsDropTable returns true if the Kind is KindDropTable.

func (Kind) IsInsert added in v0.6.0

func (k Kind) IsInsert() bool

IsInsert returns true if the Kind is KindInsert.

func (Kind) IsLoad added in v0.6.0

func (k Kind) IsLoad() bool

IsLoad returns true if the Kind is KindLoad.

func (Kind) IsMerge added in v0.6.0

func (k Kind) IsMerge() bool

IsMerge returns true if the Kind is KindMerge.

func (Kind) IsRegisterSet added in v0.7.0

func (k Kind) IsRegisterSet() bool

IsRegisterSet returns true if the Kind is KindRegisterSet.

func (Kind) IsRegisterType added in v0.6.0

func (k Kind) IsRegisterType() bool

IsRegisterType returns true if the Kind is KindRegisterType.

func (Kind) IsSelect added in v0.6.0

func (k Kind) IsSelect() bool

IsSelect returns true if the Kind is KindSelect.

func (Kind) IsUnknown added in v0.6.0

func (k Kind) IsUnknown() bool

IsUnknown returns true if the Kind is KindUnknown.

func (Kind) IsUpdate added in v0.6.0

func (k Kind) IsUpdate() bool

IsUpdate returns true if the Kind is KindUpdate.

type Lineage added in v0.13.0

type Lineage struct{ Query *query.Select }

func (Lineage) Columns added in v0.13.0

func (l Lineage) Columns() map[string]ColumnOrigin

func (Lineage) Compile added in v0.13.0

func (l Lineage) Compile() *ColumnLineage

func (Lineage) RootTable added in v0.13.0

func (l Lineage) RootTable() string

type Option added in v0.5.1

type Option func(o *Options)

func WithErrorHandler added in v0.5.1

func WithErrorHandler(fn func(err error, cur *parsly.Cursor, destNode interface{}) error) Option

func WithStructuralValidation added in v0.13.0

func WithStructuralValidation() Option

WithStructuralValidation rejects unbalanced parentheses and unclosed quotes/comments before parsing. It does not promise full dialect validation.

type Options added in v0.5.1

type Options struct {
	// contains filtered or unexported fields
}

type Stringifier added in v0.13.0

type Stringifier struct{ PreserveWindow bool }

Stringifier configures AST rendering without changing existing consumers.

func (Stringifier) String added in v0.13.0

func (s Stringifier) String(n node.Node) string

String renders a node, optionally retaining authored LIMIT/OFFSET clauses.

type TableIdentifierParser added in v0.13.0

type TableIdentifierParser struct {
	Product string
}

TableIdentifierParser configures logical table-name parsing. The zero value preserves ordinary delimited identifiers. Product "BigQuery" recognizes whole-path backticks and legacy brackets/colon separators. Parts never emits SQL.

func (TableIdentifierParser) Parts added in v0.13.0

func (p TableIdentifierParser) Parts(source string) ([]string, error)

type Token

type Token int

Token represents a token

Directories

Path Synopsis
Package source provides source-preserving SQL lexical operations.
Package source provides source-preserving SQL lexical operations.

Jump to

Keyboard shortcuts

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