Class: Ciql::Client::Binary

Inherits:
Object
  • Object
show all
Includes:
Log
Defined in:
lib/ciql/client/binary.rb

Constant Summary

Constants included from Log

Log::DEFAULT_LOG_FORMAT

Instance Method Summary collapse

Methods included from Log

#log

Constructor Details

#initialize(options = {}) ⇒ Binary

Returns a new instance of Binary.



10
11
12
13
14
15
16
17
# File 'lib/ciql/client/binary.rb', line 10

def initialize(options={})
  @options = {
    logger:               Ciql.logger,
    connections_per_node: 2,
  }.merge(options)
  @log_format = @options.delete(:log_format)
  @options[:hosts] = @options.delete(:host) { '127.0.0.1' }.split(',')
end

Instance Method Details

#connectionObject



19
20
21
# File 'lib/ciql/client/binary.rb', line 19

def connection
  @connection ||= Cql::Client.connect(@options)
end

#disconnect!Object



45
46
47
# File 'lib/ciql/client/binary.rb', line 45

def disconnect!
  connection.close
end

#execute(statement, *arguments) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/ciql/client/binary.rb', line 23

def execute(statement, *arguments)
  bind_variables    = arguments.shift statement.count('?')
  bound_statement   = Ciql::Sanitize.sanitize(statement, *bind_variables)
  consistency_level = arguments.shift or :quorum

  result = nil
  times = Benchmark.measure do
    result = connection.execute(
      bound_statement,
      consistency: consistency_level
    )
  end

  log(
    duration:    times.real * 10**3,
    query:       bound_statement,
    consistency: consistency_level.to_s.upcase
  )

  result
end