parser

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2026 License: AGPL-3.0 Imports: 13 Imported by: 0

Documentation

Overview

Package parser converts PostgreSQL and MySQL 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.

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 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.

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