Module: ClickHouse::Extend::ConnectionSelective

Included in:
Connection
Defined in:
lib/click_house/extend/connection_selective.rb

Instance Method Summary collapse

Instance Method Details

#select_all(sql) ⇒ ResultSet

Returns:

  • (ResultSet)


7
8
9
10
# File 'lib/click_house/extend/connection_selective.rb', line 7

def select_all(sql)
  response = get(body: sql, query: { default_format: 'JSON' })
  Response::Factory.response(response, config)
end

#select_one(sql) ⇒ Object



26
27
28
29
# File 'lib/click_house/extend/connection_selective.rb', line 26

def select_one(sql)
  response = get(body: sql, query: { default_format: 'JSON' })
  Response::Factory.response(response, config).first
end

#select_value(sql) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/click_house/extend/connection_selective.rb', line 12

def select_value(sql)
  response = get(body: sql, query: { default_format: 'JSON' })
  got = Response::Factory.response(response, config).first

  case got
  when Hash
    Array(got).dig(0, -1) # get a value of a first key for JSON format
  when Array
    got[0] # for CSV format
  else
    got # for RowBinary format
  end
end