Class: ClickhouseNative::Client

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/clickhouse_native/client.rb,
lib/clickhouse_native/logging.rb,
ext/clickhouse_native/client.cpp

Constant Summary

Constants included from Logging

Logging::LEVEL

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Logging

#execute, #insert_block, #query, #query_each, #query_value

Instance Attribute Details

#databaseObject (readonly)

Returns the value of attribute database.



5
6
7
# File 'lib/clickhouse_native/client.rb', line 5

def database
  @database
end

#hostObject (readonly)

Returns the value of attribute host.



5
6
7
# File 'lib/clickhouse_native/client.rb', line 5

def host
  @host
end

#loggerObject

Returns the value of attribute logger.



60
61
62
# File 'lib/clickhouse_native/logging.rb', line 60

def logger
  @logger
end

#portObject (readonly)

Returns the value of attribute port.



5
6
7
# File 'lib/clickhouse_native/client.rb', line 5

def port
  @port
end

Instance Method Details

#describe_table(table, db_name: nil) ⇒ Object



7
8
9
10
# File 'lib/clickhouse_native/client.rb', line 7

def describe_table(table, db_name: nil)
  fq = db_name ? "#{db_name}.#{table}" : table
  query("DESCRIBE TABLE #{fq}")
end

#insert(table, rows, columns: nil, db_name: nil, types: nil) ⇒ Object

insert(table, rows, columns: nil, db_name: nil, types: nil)

rows may be Array<Hash=> Object> or Array<Array>. columns defaults to the first hash’s keys (for Array<Hash>) or all table columns in DDL order (for Array<Array>). types may be supplied to skip the DESCRIBE lookup.

Hash keys not present in the schema raise ArgumentError — if you need to insert a subset, pass ‘columns:` explicitly.



21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/clickhouse_native/client.rb', line 21

def insert(table, rows, columns: nil, db_name: nil, types: nil)
  return 0 if rows.empty?

  fq = db_name ? "#{db_name}.#{table}" : table
  col_pairs =
    if types && columns
      zip_columns_and_types(columns, types)
    else
      columns_from_schema(table, rows, columns, db_name, fq)
    end
  row_arrays = rows.first.is_a?(Hash) ? hash_rows_to_arrays(rows, col_pairs) : rows

  insert_block(fq, col_pairs, row_arrays)
end

#inspectObject



36
37
38
# File 'lib/clickhouse_native/client.rb', line 36

def inspect
  "#<#{self.class} #{host}:#{port}/#{database}>"
end