Documentation
¶
Overview ¶
Package sqlparse turns raw SQL text into the query and expression nodes of package github.com/aita/sqlkit/sql — the inverse of sqlkit's build-then- compile flow.
This package holds only the dialect-agnostic surface: the Parser interface every frontend implements, the shared error helpers, and small conveniences such as ParseOne. It deliberately depends on nothing but the sql package, so callers who only need the abstraction do not pull a parser's (often heavy) dependency tree.
A concrete frontend lives in its own subpackage and module so its parser dependency stays isolated, for example github.com/aita/sqlkit/x/sqlparse/postgres, which is backed by pg_query_go. Additional dialects (MySQL, ...) can be added the same way.
Each frontend registers itself under its dialect name (matching sql.Dialect.Name()) from init, so blank-importing a frontend makes its parser resolvable by name through Register and For without coupling callers to the frontend's (often heavy) dependency tree.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrNoStatement = errors.New("sqlkit/sqlparse: no statement")
ErrNoStatement is returned by ParseOne when the input holds no statement.
Functions ¶
func ParseOne ¶
ParseOne parses text with p and requires exactly one statement, returning an error when the input holds none or more than one.
func Register ¶
Register associates a parser factory with a dialect name (matching sql.Dialect.Name(), e.g. "postgres"). A frontend calls this from its init, so blank-importing the frontend makes its parser discoverable through For. Registering the same name twice keeps the most recent factory.
func Unsupported ¶
Unsupported builds an UnsupportedError for the named construct.
func Unsupportedf ¶
Unsupportedf builds an UnsupportedError with a formatted construct name.
Types ¶
type Parser ¶
Parser converts SQL text of one dialect into sqlkit/sql queries. A single input may hold several statements, so Parse returns one sql.Query per statement in source order.
type UnsupportedError ¶
type UnsupportedError struct {
Construct string
}
UnsupportedError reports a SQL construct a frontend recognized but cannot yet represent as a sqlkit/sql node. Construct describes the offending node, e.g. "GROUPING SETS" or "expression node *pg_query.A_ArrayExpr".
func (*UnsupportedError) Error ¶
func (e *UnsupportedError) Error() string