Class: ClickHouse::Client::Database
- Inherits:
-
Object
- Object
- ClickHouse::Client::Database
- Defined in:
- lib/click_house/client/database.rb
Instance Attribute Summary collapse
-
#database ⇒ Object
readonly
Returns the value of attribute database.
Instance Method Summary collapse
- #build_custom_uri(extra_variables: {}) ⇒ Object
- #headers ⇒ Object
-
#initialize(database:, url:, username:, password:, variables: {}) ⇒ Database
constructor
A new instance of Database.
- #uri ⇒ Object
- #with_default_database ⇒ Object
Constructor Details
#initialize(database:, url:, username:, password:, variables: {}) ⇒ Database
Returns a new instance of Database.
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/click_house/client/database.rb', line 8 def initialize(database:, url:, username:, password:, variables: {}) @database = database @url = url @username = username @password = password @variables = { database:, enable_http_compression: 1 # enable HTTP compression by default }.merge(variables).freeze end |
Instance Attribute Details
#database ⇒ Object (readonly)
Returns the value of attribute database.
6 7 8 |
# File 'lib/click_house/client/database.rb', line 6 def database @database end |
Instance Method Details
#build_custom_uri(extra_variables: {}) ⇒ Object
23 24 25 26 27 |
# File 'lib/click_house/client/database.rb', line 23 def build_custom_uri(extra_variables: {}) parsed = Addressable::URI.parse(@url) parsed.query_values = @variables.merge(extra_variables) parsed end |
#headers ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/click_house/client/database.rb', line 29 def headers @headers ||= { 'X-ClickHouse-User' => @username, 'X-ClickHouse-Key' => @password, 'X-ClickHouse-Format' => 'JSON' # always return JSON data }.freeze end |
#uri ⇒ Object
19 20 21 |
# File 'lib/click_house/client/database.rb', line 19 def uri @uri ||= build_custom_uri end |
#with_default_database ⇒ Object
37 38 39 40 41 42 43 44 45 |
# File 'lib/click_house/client/database.rb', line 37 def with_default_database self.class.new( database: 'default', url: @url, username: @username, password: @password, variables: @variables.merge(database: 'default') ) end |