sqlglot

package
v1.0.6 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2025 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package sqlglot exposes a sqlglot-like API for Go. It wraps internal/ANTLR-based parsing to produce stable "signatures" (normalized SQL digests) and parameter extraction, inspired by python sqlglot.

Typical usage:

dig, params, err := sqlglot.Signature(sql, sqlglot.Options{Dialect: sqlglot.Postgres})

Index

Constants

View Source
const (
	MySQL     = core.MySQL
	Postgres  = core.Postgres
	SQLServer = core.SQLServer
	Oracle    = core.Oracle
	SQLite    = core.SQLite
	Snowflake = core.Snowflake
)

Variables

View Source
var ErrNotImplemented = errors.New("not implemented")

Functions

func ExtractFamily added in v1.0.4

func ExtractFamily(sql string, opt Options) (string, error)

ExtractFamily:单独获取 Family key 的便捷函数。

func Parse

func Parse(sql string, opt Options) (any, error)

Parse returns AST nodes (placeholder for future AST integration).

func ParseOne

func ParseOne(sql string, opt Options) (any, error)

ParseOne returns a single AST node (placeholder).

func Transpile

func Transpile(sql string, from Dialect, to Dialect, opt Options) (string, error)

Transpile converts SQL between dialects (placeholder).

Types

type Dialect

type Dialect = core.Dialect

Re-export core enums so users don't import internal.

type ExParam

type ExParam = core.ExParam

Also surface core Options/Result/ExParam for convenience.

func ExtractParams

func ExtractParams(sql string, opt Options) ([]ExParam, error)

ExtractParams returns only the parameters discovered in SQL.

func Signature

func Signature(sql string, opt Options) (digest string, params []ExParam, types []string, err error)

Signature normalizes SQL into a stable digest and extracts parameters. This mirrors sqlglot's top-level convenience APIs (parse/transpile/normalize), but focuses on digest/params which your engine specializes in.

func SignatureWithFamily added in v1.0.4

func SignatureWithFamily(sql string, opt Options) (digest string, family string, params []ExParam, types []string, err error)

SignatureWithFamily:在旧接口的基础上,追加 Family; 便于渐进式迁移,不想改调用点结构体时可用此函数。

type Options

type Options = core.Options

Also surface core Options/Result/ExParam for convenience.

type Result

type Result = core.Result

Also surface core Options/Result/ExParam for convenience.

func ResultFor

func ResultFor(sql string, opt Options) (Result, error)

ResultFor mirrors your core Result for callers that prefer one-shot struct return.

Jump to

Keyboard shortcuts

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