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 ¶
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.