Ruby bindings for polyglot-sql — a Rust-based SQL transpiler supporting 30+ database dialects.
Add to your Gemfile:
gem "polyglot-sql"Requires Rust toolchain for compilation. Install via rustup.
require "polyglot"
# PostgreSQL to MySQL
Polyglot.transpile("SELECT NOW()", from: :postgres, to: :mysql)
# => ["SELECT CURRENT_TIMESTAMP()"]
# PostgreSQL to Snowflake
Polyglot.transpile("SELECT CAST(x AS TEXT)", from: :postgres, to: :snowflake)
# => ["SELECT CAST(x AS TEXT)"]ast = Polyglot.parse("SELECT 1", dialect: :postgres)
# => [{"select" => {...}}]
ast = Polyglot.parse_one("SELECT 1", dialect: :postgres)
# => {"select" => {...}}ast = Polyglot.parse_one("SELECT 1", dialect: :postgres)
Polyglot.generate(ast, dialect: :mysql)
# => "SELECT 1"Polyglot.format("SELECT a, b FROM t WHERE x = 1", dialect: :postgres)result = Polyglot.validate("SELECT 1", dialect: :postgres)
result.valid? # => true
result.errors # => []
result = Polyglot.validate("SELEC 1")
result.valid? # => false
result.errors.first.message # => "..."Polyglot.dialects
# => ["generic", "athena", "bigquery", "clickhouse", ..., "tsql"]- Generic
- Athena
- BigQuery
- ClickHouse
- CockroachDB
- Databricks
- Doris
- Dremio
- Drill
- Druid
- DuckDB
- Dune
- Exasol
- Fabric
- Hive
- Materialize
- MySQL
- Oracle
- PostgreSQL
- Presto
- Redshift
- RisingWave
- SingleStore
- Snowflake
- Solr
- Spark
- SQLite
- StarRocks
- Tableau
- Teradata
- TiDB
- Trino
- T-SQL
Polyglot::Error # Base error class
Polyglot::ParseError # SQL parsing errors
Polyglot::GenerateError # SQL generation errors
Polyglot::UnsupportedError # Unsupported dialect features- Unknown dialects raise
ArgumentError(fortranspile,parse,parse_one,generate,format, andvalidate). generateraisesPolyglot::GenerateErrorfor invalid AST payloads.- Invalid AST error messages are concise and include line/column context when available.
bundle install
bundle exec rake # compile + test
bundle exec rake compile # compile only
bundle exec rake spec # test only
bundle exec standardrb # lint
bundle exec rake docs:dialects # sync README dialect listBuildkite runs:
- Ruby build + test matrix on Ruby 3.2, 3.3, 3.4, and 4.0
- Ruby lint (
standardrb) - Rust checks (
cargo checkandcargo clippy -- -D warnings)
MIT