polyglot

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: May 21, 2026 License: MIT Imports: 4 Imported by: 0

README

简介

这个项目是由 DeepSeek 生成的 polyglot purego bind, 以便在 golang 中使用 polyglot

注: 我不熟悉 C, 但我感觉大部分没问题

Documentation

Overview

Package polyglot_sql provides purego bindings for the polyglot_sql C library.

Before calling any functions, you must load the library using LoadLibrary.

Example:

err := polyglot_sql.LoadLibrary("libpolyglot_sql.so")
if err != nil { ... }
ast, err := polyglot_sql.Parse("SELECT 1", "generic")

Index

Constants

View Source
const (
	StatusSuccess            = 0
	StatusParseError         = 1
	StatusGenerateError      = 2
	StatusTranspileError     = 3
	StatusValidationError    = 4
	StatusInvalidArgument    = 5
	StatusSerializationError = 6
	StatusInternalError      = 99
)

Status codes returned by the library.

Variables

This section is empty.

Functions

func AnnotateTypes

func AnnotateTypes(sql, dialect, schemaJSON string) (string, error)

AnnotateTypes parses SQL and annotates the AST with inferred type information. schemaJSON can be empty to run without schema.

func DialectCount

func DialectCount() int32

DialectCount returns the number of supported built-in dialects.

func DialectList

func DialectList() (string, error)

DialectList returns the supported dialect names as a JSON array string.

func Diff

func Diff(sql1, sql2, dialect string) (string, error)

Diff computes the AST diff between two SQL statements.

func Format

func Format(sql, dialect string) (string, error)

Format pretty-prints SQL for a dialect.

func FormatWithOptions

func FormatWithOptions(sql, dialect, optionsJSON string) (string, error)

FormatWithOptions pretty-prints SQL with explicit formatting guard options. optionsJSON must be a JSON object compatible with FormatGuardOptions, e.g. `{"maxInputBytes":16777216,"maxTokens":1000000}`.

func Generate

func Generate(astJSON, dialect string) (string, error)

Generate generates SQL from AST JSON.

func Lineage

func Lineage(columnName, sql, dialect string) (string, error)

Lineage traces column lineage in a SQL statement.

func LineageWithSchema

func LineageWithSchema(columnName, sql, schemaJSON, dialect string) (string, error)

LineageWithSchema traces column lineage using schema metadata.

func LoadLibrary

func LoadLibrary(libPath string) error

LoadLibrary loads the polyglot_sql shared library from the given path and registers all functions. The path must be the full path or a name resolvable by dlopen (e.g. "libpolyglot_sql.so").

func Optimize

func Optimize(sql, dialect string) (string, error)

Optimize parses, optimizes (full pipeline), and generates SQL.

func Parse

func Parse(sql, dialect string) (string, error)

Parse parses SQL into an AST JSON string (array of expressions).

func ParseOne

func ParseOne(sql, dialect string) (string, error)

ParseOne parses a single SQL statement into a JSON AST object.

func QualifyTables

func QualifyTables(astJSON, optionsJSON string) (string, error)

QualifyTables qualifies table references in AST JSON.

func RenameTablesWithOptions

func RenameTablesWithOptions(astJSON, mappingJSON, optionsJSON string) (string, error)

RenameTablesWithOptions renames tables in AST JSON with options.

func SourceTables

func SourceTables(columnName, sql, dialect string) (string, error)

SourceTables gets source tables that contribute to a column.

func Tokenize

func Tokenize(sql, dialect string) (string, error)

Tokenize tokenizes SQL into a JSON array of tokens.

func Transpile

func Transpile(sql, fromDialect, toDialect string) (string, error)

Transpile transpiles SQL between dialects.

func TranspileWithOptions

func TranspileWithOptions(sql, fromDialect, toDialect, optionsJSON string) (string, error)

TranspileWithOptions transpiles SQL with explicit transpile options. optionsJSON must be a JSON object compatible with TranspileOptions, e.g. `{"pretty":true}`.

func Validate

func Validate(sql, dialect string) (valid bool, errorsJSON string, err error)

Validate checks SQL syntax for a dialect. It returns valid (bool), a JSON array of errors (if any), and any top-level error.

func Version

func Version() string

Version returns the library version string. The returned string is statically allocated and must not be freed.

Types

This section is empty.

Jump to

Keyboard shortcuts

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