transpiler

package
v1.14.0 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package transpiler converts SQL from one dialect to another by parsing the input SQL, applying a chain of rewrite rules that mutate dialect-specific AST constructs in place, and then reformatting the result.

Supported dialect pairs:

  • MySQL → PostgreSQL
  • PostgreSQL → MySQL
  • PostgreSQL → SQLite

For unsupported dialect pairs the SQL is parsed and reformatted without any dialect-specific rewrites (passthrough with normalisation).

Example:

result, err := transpiler.Transpile(
    "CREATE TABLE t (id INT AUTO_INCREMENT PRIMARY KEY)",
    keywords.DialectMySQL,
    keywords.DialectPostgreSQL,
)
// result: "CREATE TABLE t (id SERIAL PRIMARY KEY)"

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Transpile

func Transpile(sql string, from, to keywords.SQLDialect) (string, error)

Transpile parses sql in the from dialect, applies all registered rewrite rules for the (from → to) dialect pair, and returns the reformatted SQL.

If from == to, the SQL is parsed and reformatted with no rewrites applied. If no rules are registered for the pair, the SQL is returned normalised (parsed and reformatted without dialect-specific changes).

Types

type RewriteRule

type RewriteRule func(stmt ast.Statement) error

RewriteRule is a function that mutates an AST statement in-place to rewrite dialect-specific constructs. It returns an error if rewriting fails.

func RulesFor

func RulesFor(from, to keywords.SQLDialect) []RewriteRule

RulesFor returns the registered rewrite rules for a dialect pair. Returns nil (empty) for unregistered or same-dialect pairs. Exported for testing.

Directories

Path Synopsis
Package rules contains individual dialect rewrite rules used by the transpiler.
Package rules contains individual dialect rewrite rules used by the transpiler.

Jump to

Keyboard shortcuts

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