Module: Polyglot
- Defined in:
- lib/polyglot.rb,
lib/polyglot/version.rb,
lib/polyglot/validation_result.rb
Defined Under Namespace
Classes: ValidationError, ValidationResult
Constant Summary collapse
- VERSION =
"0.1.0"
Class Method Summary collapse
-
.format(sql, dialect: :generic) ⇒ String
Format (pretty-print) SQL.
-
.generate(ast, dialect: :generic) ⇒ String
Generate SQL from an AST expression.
-
.parse(sql, dialect: :generic) ⇒ Array<Hash>
Parse SQL into an abstract syntax tree.
-
.parse_one(sql, dialect: :generic) ⇒ Hash
Parse a single SQL statement into an AST.
-
.transpile(sql, from:, to:) ⇒ Array<String>
Transpile SQL from one dialect to another.
-
.validate(sql, dialect: :generic) ⇒ Polyglot::ValidationResult
Validate SQL syntax.
Class Method Details
.format(sql, dialect: :generic) ⇒ String
Format (pretty-print) SQL.
85 86 87 |
# File 'lib/polyglot.rb', line 85 def format(sql, dialect: :generic) _format(sql, dialect.to_s) end |
.generate(ast, dialect: :generic) ⇒ String
Generate SQL from an AST expression.
71 72 73 74 |
# File 'lib/polyglot.rb', line 71 def generate(ast, dialect: :generic) json = ast.is_a?(String) ? ast : JSON.generate(ast) _generate(json, dialect.to_s) end |
.parse(sql, dialect: :generic) ⇒ Array<Hash>
Parse SQL into an abstract syntax tree.
43 44 45 |
# File 'lib/polyglot.rb', line 43 def parse(sql, dialect: :generic) JSON.parse(_parse(sql, dialect.to_s)) end |
.parse_one(sql, dialect: :generic) ⇒ Hash
Parse a single SQL statement into an AST.
57 58 59 |
# File 'lib/polyglot.rb', line 57 def parse_one(sql, dialect: :generic) JSON.parse(_parse_one(sql, dialect.to_s)) end |
.transpile(sql, from:, to:) ⇒ Array<String>
Transpile SQL from one dialect to another.
29 30 31 |
# File 'lib/polyglot.rb', line 29 def transpile(sql, from:, to:) _transpile(sql, from.to_s, to.to_s) end |
.validate(sql, dialect: :generic) ⇒ Polyglot::ValidationResult
Validate SQL syntax.
104 105 106 107 |
# File 'lib/polyglot.rb', line 104 def validate(sql, dialect: :generic) data = JSON.parse(_validate(sql, dialect.to_s)) ValidationResult.new(data) end |