sqlglot 0.1.0-aarch64-linux-gnu

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Sqlglot
4
+ # Rails integration. Loaded automatically when +Rails::Railtie+ is
5
+ # defined (see +lib/sqlglot.rb+).
6
+ #
7
+ # @example config/application.rb
8
+ # config.sqlglot.default_dialect = :postgres
9
+ class Railtie < Rails::Railtie
10
+ config.sqlglot = ActiveSupport::OrderedOptions.new
11
+
12
+ initializer "sqlglot.configure" do |app|
13
+ cfg = app.config.sqlglot
14
+
15
+ Sqlglot.configure do |c|
16
+ c.default_dialect = cfg.default_dialect if cfg.respond_to?(:default_dialect) && cfg.default_dialect
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Sqlglot
4
+ VERSION = "0.1.0"
5
+ end
data/lib/sqlglot.rb ADDED
@@ -0,0 +1,110 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "sqlglot/version"
4
+ require_relative "sqlglot/error"
5
+ require_relative "sqlglot/dialect"
6
+ require_relative "sqlglot/native"
7
+ require_relative "sqlglot/ast_walker"
8
+ require_relative "sqlglot/query"
9
+
10
+ # Load the Railtie only when Rails is present.
11
+ require_relative "sqlglot/railtie" if defined?(Rails::Railtie)
12
+
13
+ # Sqlglot wraps the sql-glot-rust library, providing SQL parsing,
14
+ # transpilation across 30+ dialects, and query metadata extraction.
15
+ #
16
+ # @example Transpile SQL between dialects
17
+ # Sqlglot.transpile("SELECT NOW()", from: :postgres, to: :bigquery)
18
+ # # => "SELECT CURRENT_TIMESTAMP()"
19
+ #
20
+ # @example Parse SQL into an AST Hash
21
+ # ast = Sqlglot.parse("SELECT a FROM t", dialect: :mysql)
22
+ # # => {"Select" => {"columns" => [...], ...}}
23
+ #
24
+ # @example Extract query metadata
25
+ # q = Sqlglot::Query.new("SELECT a FROM users AS u JOIN orders AS o ON u.id = o.user_id")
26
+ # q.tables # => ["users", "orders"]
27
+ # q.columns_dict # => {select: ["a"], join: ["users.id", "orders.user_id"]}
28
+ module Sqlglot
29
+ # ── Configuration ────────────────────────────────────────────────────
30
+
31
+ class Configuration
32
+ # Default dialect used when no dialect is specified.
33
+ # @return [Symbol, String, nil]
34
+ attr_accessor :default_dialect
35
+
36
+ def initialize
37
+ @default_dialect = nil
38
+ end
39
+ end
40
+
41
+ class << self
42
+ # @return [Configuration]
43
+ def configuration
44
+ @configuration ||= Configuration.new
45
+ end
46
+
47
+ # Yields the configuration object for modification.
48
+ #
49
+ # @example
50
+ # Sqlglot.configure do |config|
51
+ # config.default_dialect = :postgres
52
+ # end
53
+ def configure
54
+ yield(configuration)
55
+ end
56
+
57
+ # ── Public API ───────────────────────────────────────────────────
58
+
59
+ # Parse a SQL string into a Ruby Hash representing the AST.
60
+ #
61
+ # @param sql [String] the SQL to parse
62
+ # @param dialect [Symbol, String, nil] source dialect (default: configured or ANSI)
63
+ # @return [Hash] the deserialized AST
64
+ # @raise [Sqlglot::ParseError] if parsing fails
65
+ def parse(sql, dialect: nil)
66
+ dialect_str = resolve_dialect(dialect)
67
+ json = Native.parse(sql, dialect_str)
68
+ JSON.parse(json)
69
+ end
70
+
71
+ # Transpile SQL from one dialect to another.
72
+ #
73
+ # @param sql [String] the SQL to transpile
74
+ # @param from [Symbol, String, nil] source dialect
75
+ # @param to [Symbol, String, nil] target dialect
76
+ # @return [String] the transpiled SQL
77
+ # @raise [Sqlglot::TranspileError] if transpilation fails
78
+ def transpile(sql, from: nil, to: nil)
79
+ from_str = resolve_dialect(from)
80
+ to_str = resolve_dialect(to)
81
+ Native.transpile(sql, from_str, to_str)
82
+ end
83
+
84
+ # Generate SQL from an AST Hash for a given dialect.
85
+ #
86
+ # @param ast [Hash] an AST previously returned by {.parse}
87
+ # @param dialect [Symbol, String, nil] target dialect
88
+ # @return [String] the generated SQL
89
+ # @raise [Sqlglot::GenerateError] if generation fails
90
+ def generate(ast, dialect: nil)
91
+ dialect_str = resolve_dialect(dialect)
92
+ ast_json = JSON.generate(ast)
93
+ Native.generate(ast_json, dialect_str)
94
+ end
95
+
96
+ # Return the version of the underlying sql-glot-rust library.
97
+ #
98
+ # @return [String] e.g. "0.10.0"
99
+ def version
100
+ Native.version
101
+ end
102
+
103
+ private
104
+
105
+ def resolve_dialect(name)
106
+ name = configuration.default_dialect if name.nil?
107
+ Dialect.resolve(name)
108
+ end
109
+ end
110
+ end
data/sqlglot.gemspec ADDED
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/sqlglot/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "sqlglot"
7
+ spec.version = Sqlglot::VERSION
8
+ spec.authors = ["Accountaim"]
9
+ spec.summary = "Ruby wrapper for sql-glot-rust: a SQL parser, optimizer, and transpiler"
10
+ spec.description = <<~DESC
11
+ A Ruby gem that wraps the sql-glot-rust library via FFI, providing SQL parsing,
12
+ transpilation between 30+ dialects, and query metadata extraction (tables, columns,
13
+ aliases, subqueries, CTEs, etc.) for use in Rails applications.
14
+ DESC
15
+ spec.homepage = "https://github.com/AccountAim/sql-glot-ruby"
16
+ spec.license = "MIT"
17
+ spec.required_ruby_version = ">= 3.0.0"
18
+
19
+ spec.files = Dir.chdir(__dir__) do
20
+ Dir["{lib,ext}/**/*", "Gemfile", "Rakefile", "sqlglot.gemspec"]
21
+ end
22
+
23
+ spec.require_paths = ["lib"]
24
+ spec.extensions = ["ext/sqlglot_rust/extconf.rb"]
25
+
26
+ spec.add_dependency "ffi", "~> 1.15"
27
+
28
+ spec.metadata = {
29
+ "source_code_uri" => "https://github.com/AccountAim/sql-glot-ruby",
30
+ "rubygems_mfa_required" => "true"
31
+ }
32
+ end
metadata ADDED
@@ -0,0 +1,74 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sqlglot
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: aarch64-linux-gnu
6
+ authors:
7
+ - Accountaim
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2026-06-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: ffi
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.15'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.15'
27
+ description: |
28
+ A Ruby gem that wraps the sql-glot-rust library via FFI, providing SQL parsing,
29
+ transpilation between 30+ dialects, and query metadata extraction (tables, columns,
30
+ aliases, subqueries, CTEs, etc.) for use in Rails applications.
31
+ email:
32
+ executables: []
33
+ extensions: []
34
+ extra_rdoc_files: []
35
+ files:
36
+ - Gemfile
37
+ - Rakefile
38
+ - ext/sqlglot_rust/extconf.rb
39
+ - lib/sqlglot.rb
40
+ - lib/sqlglot/ast_walker.rb
41
+ - lib/sqlglot/dialect.rb
42
+ - lib/sqlglot/error.rb
43
+ - lib/sqlglot/libsqlglot_rust.so
44
+ - lib/sqlglot/native.rb
45
+ - lib/sqlglot/query.rb
46
+ - lib/sqlglot/railtie.rb
47
+ - lib/sqlglot/version.rb
48
+ - sqlglot.gemspec
49
+ homepage: https://github.com/AccountAim/sql-glot-ruby
50
+ licenses:
51
+ - MIT
52
+ metadata:
53
+ source_code_uri: https://github.com/AccountAim/sql-glot-ruby
54
+ rubygems_mfa_required: 'true'
55
+ post_install_message:
56
+ rdoc_options: []
57
+ require_paths:
58
+ - lib
59
+ required_ruby_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: 3.0.0
64
+ required_rubygems_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ requirements: []
70
+ rubygems_version: 3.5.22
71
+ signing_key:
72
+ specification_version: 4
73
+ summary: 'Ruby wrapper for sql-glot-rust: a SQL parser, optimizer, and transpiler'
74
+ test_files: []