Sha256: d6dd2493cb0661e028677be31a26bdb31b183788b3168003bb97034c5752eabb

Contents?: true

Size: 804 Bytes

Versions: 3

Compression:

Stored size: 804 Bytes

Contents

require "clickhouse/connection/client"
require "clickhouse/connection/logger"
require "clickhouse/connection/query"

module Clickhouse
  class Connection

    DEFAULT_CONFIG = {
      :scheme => "http",
      :host => "localhost",
      :port => 8123
    }

    include Client
    include Logger
    include Query

    def initialize(config = {})
      @config = normalize_config(config)
    end

  private

    def normalize_config(config)
      config = config.inject({}) do |hash, (key, value)|
        hash[key.to_sym] = value
        hash
      end

      if config[:url]
        uri = URI config[:url]
        config[:scheme] = uri.scheme
        config[:host] = uri.host
        config[:port] = uri.port
        config.delete(:url)
      end

      DEFAULT_CONFIG.merge(config)
    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
clickhouse-0.1.4 lib/clickhouse/connection.rb
clickhouse-0.1.3 lib/clickhouse/connection.rb
clickhouse-0.1.2 lib/clickhouse/connection.rb