Sha256: fe70e02f1e62179789be2a03a394c70ce43303cb534c57a1c3f59e87eb7a9882

Contents?: true

Size: 745 Bytes

Versions: 8

Compression:

Stored size: 745 Bytes

Contents

module Clickhouse
  class Connection
    module Query
      class ResultRow < Array

        def initialize(values = [], keys = nil)
          super values
          @keys = normalize_keys(keys)
        end

        def to_hash(symbolize = false)
          @hash ||= begin
            keys = symbolize ? @keys.collect(&:to_sym) : @keys
            Hash[keys.zip(self)]
          end
        end

      private

        def normalize_keys(keys)
          if keys
            keys.collect do |key|
              key.match(/^any\(([^\)]+)\)$/)
              $1 || key
            end
          else
            (0..(size - 1)).collect do |index|
              "column#{index}"
            end
          end
        end

      end
    end
  end
end

Version data entries

8 entries across 8 versions & 2 rubygems

Version Path
ch-client-0.0.1 lib/clickhouse/connection/query/result_row.rb
clickhouse-0.1.10 lib/clickhouse/connection/query/result_row.rb
clickhouse-0.1.9 lib/clickhouse/connection/query/result_row.rb
clickhouse-0.1.8 lib/clickhouse/connection/query/result_row.rb
clickhouse-0.1.4 lib/clickhouse/connection/query/result_row.rb
clickhouse-0.1.3 lib/clickhouse/connection/query/result_row.rb
clickhouse-0.1.2 lib/clickhouse/connection/query/result_row.rb
clickhouse-0.1.1 lib/clickhouse/connection/query/result_row.rb