sqlparse

package module
v0.0.0-...-de5c544 Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2026 License: MIT Imports: 4 Imported by: 0

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

View Source
var ErrNoStatement = errors.New("sqlkit/sqlparse: no statement")

ErrNoStatement is returned by ParseOne when the input holds no statement.

Functions

func ParseOne

func ParseOne(p Parser, text string) (sql.Query, error)

ParseOne parses text with p and requires exactly one statement, returning an error when the input holds none or more than one.

func Register

func Register(dialect string, factory func() Parser)

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

func Unsupported(construct string) error

Unsupported builds an UnsupportedError for the named construct.

func Unsupportedf

func Unsupportedf(format string, args ...any) error

Unsupportedf builds an UnsupportedError with a formatted construct name.

Types

type Parser

type Parser interface {
	Parse(text string) ([]sql.Query, error)
}

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.

func For

func For(dialect string) (Parser, bool)

For returns a parser for the named dialect, or (nil, false) when no frontend has registered it — for example when the frontend package was not imported.

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

Directories

Path Synopsis
postgres module

Jump to

Keyboard shortcuts

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