Sha256: 38a9b8bcf90873e05fcf64042044f626c4c5ee1ae282a2b6a87f826649120751

Contents?: true

Size: 556 Bytes

Versions: 8

Compression:

Stored size: 556 Bytes

Contents

require 'pg_query'
module HSQL
  # PgQuery uses Postgres' own parser to parse and then deparse each query.
  class Query < Struct.new(:ast)
    # Returns a list of queries found in the source SQL
    def self.parse(source)
      # Splits on semicolons at the end of the line, eliding any comment that
      # might be there.
      PgQuery.parse(source).parsetree.map do |ast|
        Query.new(ast)
      end
    end

    # Show the parsed query as reconstructed SQL
    def to_s
      PgQuery.deparse ast
    end
    alias_method :to_sql, :to_s
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
hsql-0.3.7 lib/hsql/query.rb
hsql-0.3.6 lib/hsql/query.rb
hsql-0.3.5 lib/hsql/query.rb
hsql-0.3.4 lib/hsql/query.rb
hsql-0.3.3 lib/hsql/query.rb
hsql-0.3.2 lib/hsql/query.rb
hsql-0.3.1 lib/hsql/query.rb
hsql-0.3.0 lib/hsql/query.rb