Class: ChConnect::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/ch_connect/config.rb

Overview

Configuration for ClickHouse connection.

Examples:

config = ChConnect::Config.new(host: "db.example.com", port: 9000)

Using URL

config = ChConnect::Config.new
config.url = "http://user:pass@localhost:8123/mydb"

Constant Summary collapse

DEFAULTS =
{
  scheme: "http",
  host: "localhost",
  port: 8123,
  database: "default",
  username: "",
  password: "",
  connection_timeout: 5,
  read_timeout: 60,
  write_timeout: 60,
  keep_alive_timeout: 8,
  pool_size: 100,
  pool_timeout: 5,
  max_retries: 3,
  instrumenter: NullInstrumenter.new
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ Config

Creates a new configuration instance.

Parameters:

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

    configuration options

Options Hash (params):

  • :scheme (String)

    URL scheme (default: “http”)

  • :host (String)

    server hostname (default: “localhost”)

  • :port (Integer)

    server port (default: 8123)

  • :database (String)

    database name (default: “default”)

  • :username (String)

    authentication username (default: “”)

  • :password (String)

    authentication password (default: “”)

  • :connection_timeout (Integer)

    connection timeout in seconds (default: 5)

  • :read_timeout (Integer)

    read timeout in seconds (default: 60)

  • :write_timeout (Integer)

    write timeout in seconds (default: 60)

  • :keep_alive_timeout (Integer)

    idle persistent connection timeout in seconds (default: 8)

  • :pool_size (Integer)

    connection pool size (default: 100)

  • :pool_timeout (Integer)

    pool checkout timeout (default: 5)

  • :max_retries (Integer)

    max retry attempts on connection errors (default: 3)



64
65
66
67
68
# File 'lib/ch_connect/config.rb', line 64

def initialize(params = {})
  DEFAULTS.merge(params).each do |key, value|
    send("#{key}=", value)
  end
end

Instance Attribute Details

#connection_timeoutString, ...

Returns:

  • (String)

    URL scheme (http or https)

  • (String)

    ClickHouse server hostname

  • (Integer)

    ClickHouse server port

  • (String)

    Database name

  • (String)

    Username for authentication

  • (String)

    Password for authentication

  • (Integer)

    Connection timeout in seconds

  • (Integer)

    Read timeout in seconds

  • (Integer)

    Write timeout in seconds

  • (Integer)

    Keep-alive timeout for idle persistent connections in seconds

  • (Integer)

    Connection pool size

  • (Integer)

    Pool checkout timeout in seconds

  • (Integer)

    Max retry attempts on connection errors

  • (#instrument)

    Instrumenter for query instrumentation



46
47
48
# File 'lib/ch_connect/config.rb', line 46

def connection_timeout
  @connection_timeout
end

#databaseString, ...

Returns:

  • (String)

    URL scheme (http or https)

  • (String)

    ClickHouse server hostname

  • (Integer)

    ClickHouse server port

  • (String)

    Database name

  • (String)

    Username for authentication

  • (String)

    Password for authentication

  • (Integer)

    Connection timeout in seconds

  • (Integer)

    Read timeout in seconds

  • (Integer)

    Write timeout in seconds

  • (Integer)

    Keep-alive timeout for idle persistent connections in seconds

  • (Integer)

    Connection pool size

  • (Integer)

    Pool checkout timeout in seconds

  • (Integer)

    Max retry attempts on connection errors

  • (#instrument)

    Instrumenter for query instrumentation



46
47
48
# File 'lib/ch_connect/config.rb', line 46

def database
  @database
end

#hostString, ...

Returns:

  • (String)

    URL scheme (http or https)

  • (String)

    ClickHouse server hostname

  • (Integer)

    ClickHouse server port

  • (String)

    Database name

  • (String)

    Username for authentication

  • (String)

    Password for authentication

  • (Integer)

    Connection timeout in seconds

  • (Integer)

    Read timeout in seconds

  • (Integer)

    Write timeout in seconds

  • (Integer)

    Keep-alive timeout for idle persistent connections in seconds

  • (Integer)

    Connection pool size

  • (Integer)

    Pool checkout timeout in seconds

  • (Integer)

    Max retry attempts on connection errors

  • (#instrument)

    Instrumenter for query instrumentation



46
47
48
# File 'lib/ch_connect/config.rb', line 46

def host
  @host
end

#instrumenterString, ...

Returns:

  • (String)

    URL scheme (http or https)

  • (String)

    ClickHouse server hostname

  • (Integer)

    ClickHouse server port

  • (String)

    Database name

  • (String)

    Username for authentication

  • (String)

    Password for authentication

  • (Integer)

    Connection timeout in seconds

  • (Integer)

    Read timeout in seconds

  • (Integer)

    Write timeout in seconds

  • (Integer)

    Keep-alive timeout for idle persistent connections in seconds

  • (Integer)

    Connection pool size

  • (Integer)

    Pool checkout timeout in seconds

  • (Integer)

    Max retry attempts on connection errors

  • (#instrument)

    Instrumenter for query instrumentation



46
47
48
# File 'lib/ch_connect/config.rb', line 46

def instrumenter
  @instrumenter
end

#keep_alive_timeoutString, ...

Returns:

  • (String)

    URL scheme (http or https)

  • (String)

    ClickHouse server hostname

  • (Integer)

    ClickHouse server port

  • (String)

    Database name

  • (String)

    Username for authentication

  • (String)

    Password for authentication

  • (Integer)

    Connection timeout in seconds

  • (Integer)

    Read timeout in seconds

  • (Integer)

    Write timeout in seconds

  • (Integer)

    Keep-alive timeout for idle persistent connections in seconds

  • (Integer)

    Connection pool size

  • (Integer)

    Pool checkout timeout in seconds

  • (Integer)

    Max retry attempts on connection errors

  • (#instrument)

    Instrumenter for query instrumentation



46
47
48
# File 'lib/ch_connect/config.rb', line 46

def keep_alive_timeout
  @keep_alive_timeout
end

#max_retriesString, ...

Returns:

  • (String)

    URL scheme (http or https)

  • (String)

    ClickHouse server hostname

  • (Integer)

    ClickHouse server port

  • (String)

    Database name

  • (String)

    Username for authentication

  • (String)

    Password for authentication

  • (Integer)

    Connection timeout in seconds

  • (Integer)

    Read timeout in seconds

  • (Integer)

    Write timeout in seconds

  • (Integer)

    Keep-alive timeout for idle persistent connections in seconds

  • (Integer)

    Connection pool size

  • (Integer)

    Pool checkout timeout in seconds

  • (Integer)

    Max retry attempts on connection errors

  • (#instrument)

    Instrumenter for query instrumentation



46
47
48
# File 'lib/ch_connect/config.rb', line 46

def max_retries
  @max_retries
end

#passwordString, ...

Returns:

  • (String)

    URL scheme (http or https)

  • (String)

    ClickHouse server hostname

  • (Integer)

    ClickHouse server port

  • (String)

    Database name

  • (String)

    Username for authentication

  • (String)

    Password for authentication

  • (Integer)

    Connection timeout in seconds

  • (Integer)

    Read timeout in seconds

  • (Integer)

    Write timeout in seconds

  • (Integer)

    Keep-alive timeout for idle persistent connections in seconds

  • (Integer)

    Connection pool size

  • (Integer)

    Pool checkout timeout in seconds

  • (Integer)

    Max retry attempts on connection errors

  • (#instrument)

    Instrumenter for query instrumentation



46
47
48
# File 'lib/ch_connect/config.rb', line 46

def password
  @password
end

#pool_sizeString, ...

Returns:

  • (String)

    URL scheme (http or https)

  • (String)

    ClickHouse server hostname

  • (Integer)

    ClickHouse server port

  • (String)

    Database name

  • (String)

    Username for authentication

  • (String)

    Password for authentication

  • (Integer)

    Connection timeout in seconds

  • (Integer)

    Read timeout in seconds

  • (Integer)

    Write timeout in seconds

  • (Integer)

    Keep-alive timeout for idle persistent connections in seconds

  • (Integer)

    Connection pool size

  • (Integer)

    Pool checkout timeout in seconds

  • (Integer)

    Max retry attempts on connection errors

  • (#instrument)

    Instrumenter for query instrumentation



46
47
48
# File 'lib/ch_connect/config.rb', line 46

def pool_size
  @pool_size
end

#pool_timeoutString, ...

Returns:

  • (String)

    URL scheme (http or https)

  • (String)

    ClickHouse server hostname

  • (Integer)

    ClickHouse server port

  • (String)

    Database name

  • (String)

    Username for authentication

  • (String)

    Password for authentication

  • (Integer)

    Connection timeout in seconds

  • (Integer)

    Read timeout in seconds

  • (Integer)

    Write timeout in seconds

  • (Integer)

    Keep-alive timeout for idle persistent connections in seconds

  • (Integer)

    Connection pool size

  • (Integer)

    Pool checkout timeout in seconds

  • (Integer)

    Max retry attempts on connection errors

  • (#instrument)

    Instrumenter for query instrumentation



46
47
48
# File 'lib/ch_connect/config.rb', line 46

def pool_timeout
  @pool_timeout
end

#portString, ...

Returns:

  • (String)

    URL scheme (http or https)

  • (String)

    ClickHouse server hostname

  • (Integer)

    ClickHouse server port

  • (String)

    Database name

  • (String)

    Username for authentication

  • (String)

    Password for authentication

  • (Integer)

    Connection timeout in seconds

  • (Integer)

    Read timeout in seconds

  • (Integer)

    Write timeout in seconds

  • (Integer)

    Keep-alive timeout for idle persistent connections in seconds

  • (Integer)

    Connection pool size

  • (Integer)

    Pool checkout timeout in seconds

  • (Integer)

    Max retry attempts on connection errors

  • (#instrument)

    Instrumenter for query instrumentation



46
47
48
# File 'lib/ch_connect/config.rb', line 46

def port
  @port
end

#read_timeoutString, ...

Returns:

  • (String)

    URL scheme (http or https)

  • (String)

    ClickHouse server hostname

  • (Integer)

    ClickHouse server port

  • (String)

    Database name

  • (String)

    Username for authentication

  • (String)

    Password for authentication

  • (Integer)

    Connection timeout in seconds

  • (Integer)

    Read timeout in seconds

  • (Integer)

    Write timeout in seconds

  • (Integer)

    Keep-alive timeout for idle persistent connections in seconds

  • (Integer)

    Connection pool size

  • (Integer)

    Pool checkout timeout in seconds

  • (Integer)

    Max retry attempts on connection errors

  • (#instrument)

    Instrumenter for query instrumentation



46
47
48
# File 'lib/ch_connect/config.rb', line 46

def read_timeout
  @read_timeout
end

#schemeString, ...

Returns:

  • (String)

    URL scheme (http or https)

  • (String)

    ClickHouse server hostname

  • (Integer)

    ClickHouse server port

  • (String)

    Database name

  • (String)

    Username for authentication

  • (String)

    Password for authentication

  • (Integer)

    Connection timeout in seconds

  • (Integer)

    Read timeout in seconds

  • (Integer)

    Write timeout in seconds

  • (Integer)

    Keep-alive timeout for idle persistent connections in seconds

  • (Integer)

    Connection pool size

  • (Integer)

    Pool checkout timeout in seconds

  • (Integer)

    Max retry attempts on connection errors

  • (#instrument)

    Instrumenter for query instrumentation



46
47
48
# File 'lib/ch_connect/config.rb', line 46

def scheme
  @scheme
end

#usernameString, ...

Returns:

  • (String)

    URL scheme (http or https)

  • (String)

    ClickHouse server hostname

  • (Integer)

    ClickHouse server port

  • (String)

    Database name

  • (String)

    Username for authentication

  • (String)

    Password for authentication

  • (Integer)

    Connection timeout in seconds

  • (Integer)

    Read timeout in seconds

  • (Integer)

    Write timeout in seconds

  • (Integer)

    Keep-alive timeout for idle persistent connections in seconds

  • (Integer)

    Connection pool size

  • (Integer)

    Pool checkout timeout in seconds

  • (Integer)

    Max retry attempts on connection errors

  • (#instrument)

    Instrumenter for query instrumentation



46
47
48
# File 'lib/ch_connect/config.rb', line 46

def username
  @username
end

#write_timeoutString, ...

Returns:

  • (String)

    URL scheme (http or https)

  • (String)

    ClickHouse server hostname

  • (Integer)

    ClickHouse server port

  • (String)

    Database name

  • (String)

    Username for authentication

  • (String)

    Password for authentication

  • (Integer)

    Connection timeout in seconds

  • (Integer)

    Read timeout in seconds

  • (Integer)

    Write timeout in seconds

  • (Integer)

    Keep-alive timeout for idle persistent connections in seconds

  • (Integer)

    Connection pool size

  • (Integer)

    Pool checkout timeout in seconds

  • (Integer)

    Max retry attempts on connection errors

  • (#instrument)

    Instrumenter for query instrumentation



46
47
48
# File 'lib/ch_connect/config.rb', line 46

def write_timeout
  @write_timeout
end

Instance Method Details

#url=(url) ⇒ void

This method returns an undefined value.

Sets configuration from a URL string.

Parameters:

  • url (String)

    ClickHouse connection URL



74
75
76
77
78
79
80
81
82
# File 'lib/ch_connect/config.rb', line 74

def url=(url)
  uri = URI(url)
  @scheme = uri.scheme
  @host = uri.host
  @port = uri.port
  @database = uri.path.delete_prefix("/")
  @username = uri.user
  @password = uri.password
end