Help us shape the future of Go! Take the 2026 Go Developer Survey

parser

package
v1.9.0 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package parser converts approved PostgreSQL, MySQL, DM8, and Oracle SQL into the frozen model AST.

PostgreSQL uses pg_query_go/v5, which embeds the PostgreSQL parser. MySQL uses Vitess vt/sqlparser v0.21.6. Vitess was selected over xwb1989/sqlparser because both expose the required AST data under Apache-2.0, while Vitess is actively maintained and offers strict DDL parsing; v0.21.6 is the release compatible with the project's Go 1.23.10 baseline.

DM8 and Oracle use a separate, dependency-free parser for the documented v0.5 read-only SELECT profile. That parser intentionally rejects every SQL construct outside the profile instead of treating either vendor as another registered dialect.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrUnparseable indicates that SQL cannot be proven to be one valid statement.
	ErrUnparseable = errors.New("SQL is not one parseable statement")
	// ErrUnsupportedDialect indicates that no approved parser exists for a dialect.
	ErrUnsupportedDialect = errors.New("unsupported database dialect")
)

Functions

This section is empty.

Types

type MySQLColumnSelectShape added in v1.3.0

type MySQLColumnSelectShape struct {
	Schema  string
	Table   string
	Alias   string
	Outputs []string
	Uses    []MySQLColumnUse
}

MySQLColumnSelectShape is a deliberately small, syntax-only description. Physical column identity and object type must still be proven on the same business connection before this shape can authorize an execution.

func ParseMySQLColumnSelectShape added in v1.3.0

func ParseMySQLColumnSelectShape(raw string) (shape MySQLColumnSelectShape, parseErr error)

ParseMySQLColumnSelectShape accepts only a single, plain base-table SELECT. It never rewrites SQL or treats parsed names as authority-bearing identities.

type MySQLColumnUse added in v1.3.0

type MySQLColumnUse struct {
	Name        string
	Usage       string
	Site        string
	OutputIndex int
}

type Parser

type Parser interface {
	Parse(sql string) (*model.AST, error)
}

Parser converts one SQL statement into the frozen AgentSQL AST.

func NewParser

func NewParser(dialect model.DBDialect) (Parser, error)

NewParser returns the approved parser implementation for dialect.

func NewYashanParser added in v0.5.0

func NewYashanParser() Parser

NewYashanParser constructs the narrow, offline Yashan dialect parser.

type PostgresClosedAssignment

type PostgresClosedAssignment struct {
	Column string
	Value  *PostgresClosedExpr
}

type PostgresClosedDML

type PostgresClosedDML struct {
	Action        string
	Relation      PostgresClosedRelation
	InsertColumns []string
	Values        [][]*PostgresClosedExpr
	Assignments   []PostgresClosedAssignment
	Where         *PostgresClosedExpr
	ASTDigest     string
	NodeCount     int
	MaxDepth      int
}

PostgresClosedDML is the deliberately small raw-tree contract used by the zero-install B5 binder. It contains names and expressions only; catalog OIDs and type identities are resolved again while relation locks are held.

func ParsePostgresClosedDML

func ParsePostgresClosedDML(sql string) (*PostgresClosedDML, error)

ParsePostgresClosedDML accepts exactly one schema-qualified INSERT VALUES, UPDATE ... WHERE, or DELETE ... WHERE statement. Every richer raw-tree node is rejected before a business connection is acquired.

type PostgresClosedError

type PostgresClosedError struct{ Kind PostgresClosedErrorKind }

func (*PostgresClosedError) Error

func (err *PostgresClosedError) Error() string

type PostgresClosedErrorKind

type PostgresClosedErrorKind string

PostgresClosedErrorKind classifies failures from the deliberately small CATALOG_CLOSED_V1 grammar. The database layer maps these classifications to stable authorization errors without retaining parser or database text.

const (
	PostgresClosedModeRequired PostgresClosedErrorKind = "mode_required"
	PostgresClosedUnsupported  PostgresClosedErrorKind = "unsupported"
	PostgresClosedColumnShape  PostgresClosedErrorKind = "column_shape"
)

func PostgresClosedErrorClass

func PostgresClosedErrorClass(err error) (PostgresClosedErrorKind, bool)

type PostgresClosedExpr

type PostgresClosedExpr struct {
	Kind        PostgresClosedExprKind
	Column      []string
	Integer     int64
	Boolean     bool
	Operator    string
	Args        []*PostgresClosedExpr
	SubLinkType string
	Subquery    *PostgresClosedSelect
}

type PostgresClosedExprKind

type PostgresClosedExprKind string
const (
	PostgresClosedString PostgresClosedExprKind = "string"
	PostgresClosedFloat  PostgresClosedExprKind = "float"
	PostgresClosedBit    PostgresClosedExprKind = "bit"
)
const (
	PostgresClosedColumn   PostgresClosedExprKind = "column"
	PostgresClosedInteger  PostgresClosedExprKind = "integer"
	PostgresClosedBoolean  PostgresClosedExprKind = "boolean"
	PostgresClosedNull     PostgresClosedExprKind = "null"
	PostgresClosedOperator PostgresClosedExprKind = "operator"
	PostgresClosedBoolExpr PostgresClosedExprKind = "bool_expr"
	PostgresClosedNullTest PostgresClosedExprKind = "null_test"
	PostgresClosedSubquery PostgresClosedExprKind = "subquery"
)

type PostgresClosedFrom

type PostgresClosedFrom struct {
	Relation *PostgresClosedRelation
	Join     *PostgresClosedJoin
}

type PostgresClosedJoin

type PostgresClosedJoin struct {
	Kind      string
	Left      *PostgresClosedFrom
	Right     *PostgresClosedFrom
	Condition *PostgresClosedExpr
}

type PostgresClosedRelation

type PostgresClosedRelation struct {
	Schema string
	Name   string
	Alias  string
}

type PostgresClosedSelect

type PostgresClosedSelect struct {
	Targets   []*PostgresClosedExpr
	From      *PostgresClosedFrom
	Where     *PostgresClosedExpr
	Relations []PostgresClosedRelation
	ASTDigest string
	NodeCount int
	MaxDepth  int
}

func ParsePostgresClosedSelect

func ParsePostgresClosedSelect(sql string) (*PostgresClosedSelect, error)

ParsePostgresClosedSelect parses one PostgreSQL SELECT into a closed raw tree. It does not resolve names or types; that must happen against a locked catalog frame. Every unrecognized query or expression form is rejected.

Jump to

Keyboard shortcuts

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