Module: Sqlglot
- Defined in:
- lib/sqlglot.rb,
lib/sqlglot/error.rb,
lib/sqlglot/query.rb,
lib/sqlglot/native.rb,
lib/sqlglot/dialect.rb,
lib/sqlglot/railtie.rb,
lib/sqlglot/version.rb,
lib/sqlglot/ast_walker.rb
Overview
Sqlglot wraps the sql-glot-rust library, providing SQL parsing, transpilation across 30+ dialects, and query metadata extraction.
Defined Under Namespace
Modules: AstWalker, Dialect, Native Classes: Configuration, Error, GenerateError, LibraryNotFoundError, ParseError, Query, Railtie, TranspileError
Constant Summary collapse
- VERSION =
"0.1.0"
Class Method Summary collapse
- .configuration ⇒ Configuration
-
.configure {|configuration| ... } ⇒ Object
Yields the configuration object for modification.
-
.generate(ast, dialect: nil) ⇒ String
Generate SQL from an AST Hash for a given dialect.
-
.parse(sql, dialect: nil) ⇒ Hash
Parse a SQL string into a Ruby Hash representing the AST.
-
.transpile(sql, from: nil, to: nil) ⇒ String
Transpile SQL from one dialect to another.
-
.version ⇒ String
Return the version of the underlying sql-glot-rust library.
Class Method Details
.configuration ⇒ Configuration
43 44 45 |
# File 'lib/sqlglot.rb', line 43 def configuration @configuration ||= Configuration.new end |
.configure {|configuration| ... } ⇒ Object
Yields the configuration object for modification.
53 54 55 |
# File 'lib/sqlglot.rb', line 53 def configure yield(configuration) end |
.generate(ast, dialect: nil) ⇒ String
Generate SQL from an AST Hash for a given dialect.
90 91 92 93 94 |
# File 'lib/sqlglot.rb', line 90 def generate(ast, dialect: nil) dialect_str = resolve_dialect(dialect) ast_json = JSON.generate(ast) Native.generate(ast_json, dialect_str) end |
.parse(sql, dialect: nil) ⇒ Hash
Parse a SQL string into a Ruby Hash representing the AST.
65 66 67 68 69 |
# File 'lib/sqlglot.rb', line 65 def parse(sql, dialect: nil) dialect_str = resolve_dialect(dialect) json = Native.parse(sql, dialect_str) JSON.parse(json) end |