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
- func AnnotateTypes(sql, dialect, schemaJSON string) (string, error)
- func DialectCount() int32
- func DialectList() (string, error)
- func Diff(sql1, sql2, dialect string) (string, error)
- func Format(sql, dialect string) (string, error)
- func FormatWithOptions(sql, dialect, optionsJSON string) (string, error)
- func Generate(astJSON, dialect string) (string, error)
- func Lineage(columnName, sql, dialect string) (string, error)
- func LineageWithSchema(columnName, sql, schemaJSON, dialect string) (string, error)
- func LoadLibrary(libPath string) error
- func Optimize(sql, dialect string) (string, error)
- func Parse(sql, dialect string) (string, error)
- func ParseOne(sql, dialect string) (string, error)
- func QualifyTables(astJSON, optionsJSON string) (string, error)
- func RenameTablesWithOptions(astJSON, mappingJSON, optionsJSON string) (string, error)
- func SourceTables(columnName, sql, dialect string) (string, error)
- func Tokenize(sql, dialect string) (string, error)
- func Transpile(sql, fromDialect, toDialect string) (string, error)
- func TranspileWithOptions(sql, fromDialect, toDialect, optionsJSON string) (string, error)
- func Validate(sql, dialect string) (valid bool, errorsJSON string, err error)
- func Version() string
Constants ¶
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 ¶
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 ¶
DialectList returns the supported dialect names as a JSON array string.
func FormatWithOptions ¶
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 LineageWithSchema ¶
LineageWithSchema traces column lineage using schema metadata.
func LoadLibrary ¶
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 QualifyTables ¶
QualifyTables qualifies table references in AST JSON.
func RenameTablesWithOptions ¶
RenameTablesWithOptions renames tables in AST JSON with options.
func SourceTables ¶
SourceTables gets source tables that contribute to a column.
func TranspileWithOptions ¶
TranspileWithOptions transpiles SQL with explicit transpile options. optionsJSON must be a JSON object compatible with TranspileOptions, e.g. `{"pretty":true}`.
Types ¶
This section is empty.