Class: ClickHouse::HTTPClient::Database

Inherits:
Data
  • Object
show all
Defined in:
lib/clickhouse/http_client/database.rb

Overview

Connection settings and headers for one registered ClickHouse database.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#headersObject (readonly)

Returns the value of attribute headers

Returns:

  • (Object)

    the current value of headers



6
7
8
# File 'lib/clickhouse/http_client/database.rb', line 6

def headers
  @headers
end

#urlObject (readonly)

Returns the value of attribute url

Returns:

  • (Object)

    the current value of url



6
7
8
# File 'lib/clickhouse/http_client/database.rb', line 6

def url
  @url
end

#variablesObject (readonly)

Returns the value of attribute variables

Returns:

  • (Object)

    the current value of variables



6
7
8
# File 'lib/clickhouse/http_client/database.rb', line 6

def variables
  @variables
end

Class Method Details

.build(database:, url:, username:, password:, variables: {}) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/clickhouse/http_client/database.rb', line 7

def self.build(database:, url:, username:, password:, variables: {})
  new(
    url: url,
    variables: {
      database: database,
      enable_http_compression: 1,
      # Buffer each response server-side before sending: without this,
      # ClickHouse commits HTTP 200 once it starts streaming, and an
      # error later in query execution (memory limit, server-side
      # timeout) is appended to the already-started body rather than
      # producing an error status.
      wait_end_of_query: 1,
    }.merge(variables).freeze,
    headers: {
      "X-ClickHouse-User" => username,
      "X-ClickHouse-Key" => password,
      "X-ClickHouse-Format" => "JSON", # always return JSON data
    }.freeze,
  )
end

Instance Method Details

#database_nameString

Returns Physical ClickHouse database name.

Returns:

  • (String)

    Physical ClickHouse database name.



29
30
31
# File 'lib/clickhouse/http_client/database.rb', line 29

def database_name
  variables.fetch(:database)
end

#uri(extra_variables = {}) ⇒ URI::HTTP

Returns Endpoint URI for this database.

Parameters:

  • extra_variables (Hash) (defaults to: {})

    Additional URL query parameters.

Returns:

  • (URI::HTTP)

    Endpoint URI for this database.



35
36
37
38
39
# File 'lib/clickhouse/http_client/database.rb', line 35

def uri(extra_variables = {})
  URI.parse(url).tap do |uri|
    uri.query = URI.encode_www_form(variables.merge(extra_variables))
  end
end