ciql 0.2.4 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bef8937cc139e4f15b216b8d4c2a9803feab92d8
4
- data.tar.gz: 4498237edc0cf34018bd3ab4603c45fdf875bf2b
3
+ metadata.gz: 5e9c50f26c2571d06b20a0af39bf3ab2ecccf4c2
4
+ data.tar.gz: a5d0b7fa17071fb32f1149de13480c24386bb854
5
5
  SHA512:
6
- metadata.gz: 39f86c6452055ecbc701ce16eb6cfc4419b2b0d938e7161b8658ef23d7c5453d2b57803a1a605c29c0a542c75474ec87d9e2acdb5b5151be8a5ff488409f7866
7
- data.tar.gz: ef5eba045ce56c4dcbcb8c375e035f5799329d989f3aca1d10ba8e0f4b44869de11fad4b7e96d0d8e3afc0f6b74099a775ec76ebfa32c035971e1ce436081790
6
+ metadata.gz: 989474129f432a99c90d264a14df177078bb071eb64acc496baee234b7553a9d2628bab218b31ecf50b87ac8fcc4b5c7f0793bd7bd8e64402f446988f37d9694
7
+ data.tar.gz: c911ed72fcaeb9823d7907bd14813bb15224ac89aa3cddc3d44723222e2bab5b4ff34239590fc021f3d49b17a4f4ebe9aefd0d49154c455bfeda6d70f33777c6
@@ -0,0 +1,48 @@
1
+ require 'cql'
2
+ require 'benchmark'
3
+
4
+ require 'ciql/client/log'
5
+
6
+ module Ciql::Client
7
+ class Binary
8
+ include Log
9
+
10
+ attr_reader :connection
11
+
12
+ def initialize(options={})
13
+ options = options.dup
14
+ @log_format = options.delete(:log_format)
15
+
16
+ options[:hosts] = options.delete(:host) { '127.0.0.1' }.split(',')
17
+ options[:logger] = Ciql.logger
18
+
19
+ @connection = Cql::Client.connect(options)
20
+ end
21
+
22
+ def execute(statement, *arguments)
23
+ bind_variables = arguments.shift statement.count('?')
24
+ bound_statement = Ciql::Sanitize.sanitize(statement, *bind_variables)
25
+ consistency_level = arguments.shift or :quorum
26
+
27
+ result = nil
28
+ times = Benchmark.measure do
29
+ result = @connection.execute(
30
+ bound_statement,
31
+ consistency: consistency_level
32
+ )
33
+ end
34
+
35
+ log(
36
+ duration: times.real * 10**3,
37
+ query: bound_statement,
38
+ consistency: consistency_level.to_s.upcase
39
+ )
40
+
41
+ result
42
+ end
43
+
44
+ def disconnect!
45
+ @connection.close
46
+ end
47
+ end
48
+ end
@@ -8,21 +8,23 @@ module Ciql::Client
8
8
  class Thrift < CassandraCQL::Database
9
9
  include Log
10
10
 
11
+ attr_reader :connection
12
+
11
13
  def initialize(options={})
12
- options = options.dup
14
+ options = options.dup
13
15
  @log_format = options.delete(:log_format)
14
16
 
15
- port = options.delete(:port) { 9160 }
16
- hosts = options.delete(:host) { '127.0.0.1' }.split(',')
17
- hosts_with_port = hosts.map { |host| [host, port].join(':') }
18
17
  retries = options.delete(:retries) { 2 }
18
+ port = options.delete(:port) { 9160 }
19
+ hosts = options.delete(:host) { '127.0.0.1' }.split(',')
20
+ hosts_with_port = hosts.map { |host| [host, port].join(':') }
19
21
  super(hosts_with_port, options, retries: retries)
20
22
  end
21
23
 
22
24
  def execute(statement, *arguments)
23
- bind_variables = arguments.shift statement.count('?')
24
- bound_statement = Ciql::Sanitize.sanitize(statement, *bind_variables)
25
- compression_type = CassandraCQL::Thrift::Compression::NONE
25
+ bind_variables = arguments.shift statement.count('?')
26
+ bound_statement = Ciql::Sanitize.sanitize(statement, *bind_variables)
27
+ compression_type = CassandraCQL::Thrift::Compression::NONE
26
28
  consistency_level = (arguments.shift or :quorum).to_s.upcase
27
29
 
28
30
  result = nil
@@ -3,7 +3,7 @@ require 'ostruct'
3
3
  module Ciql
4
4
  @@client = nil
5
5
  def self.client
6
- @@client ||= Client::Thrift.new(configuration.to_options)
6
+ @@client ||= Client::Binary.new(configuration.to_options)
7
7
  end
8
8
 
9
9
  @@configuration = nil
data/lib/ciql/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Ciql
2
- VERSION = '0.2.4'.freeze
2
+ VERSION = '0.3.0'.freeze
3
3
  end
data/lib/ciql.rb CHANGED
@@ -12,5 +12,5 @@ end
12
12
 
13
13
  require 'ciql/configuration'
14
14
  require 'ciql/sanitize'
15
- require 'ciql/client/thrift'
15
+ require 'ciql/client/binary'
16
16
  require 'ciql/rails' if defined?(Rails)
@@ -0,0 +1,30 @@
1
+ require 'spec_helper'
2
+
3
+ module Ciql::Client
4
+ describe Binary do
5
+ let(:logger) do
6
+ mock(:debug? => true, debug: nil, info: nil, warn: nil)
7
+ end
8
+
9
+ subject { described_class.new(log: logger) }
10
+
11
+ before do
12
+ Ciql.logger = logger
13
+ end
14
+
15
+ describe '#execute' do
16
+ it 'logs the query' do
17
+ subject # instantiate
18
+ logger.should_receive(:debug).with(/system.local where key = 'local' \[ONE\]/)
19
+ subject.execute('select * from system.local where key = ?', :local, :one)
20
+ end
21
+ end
22
+
23
+ describe '#disconnect!' do
24
+ it 'closes the connection' do
25
+ subject.disconnect!
26
+ subject.connection.should_not be_connected
27
+ end
28
+ end
29
+ end
30
+ end
@@ -1,8 +1,9 @@
1
1
  require 'spec_helper'
2
+ require 'ciql/client/thrift'
2
3
 
3
4
  module Ciql::Client
4
5
  describe Thrift do
5
- let(:logger) { mock(:debug? => true, :debug => nil) }
6
+ let(:logger) { mock(:debug? => true, debug: nil) }
6
7
 
7
8
  subject { described_class.new(log: logger) }
8
9
 
metadata CHANGED
@@ -1,43 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ciql
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Bradford
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-09-05 00:00:00.000000000 Z
11
+ date: 2013-12-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: cassandra-cql
14
+ name: cql-rb
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ~>
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: 1.1.1
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - ~>
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
26
+ version: 1.1.1
27
27
  - !ruby/object:Gem::Dependency
28
- name: cql-rb
28
+ name: cassandra-cql
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ~>
32
32
  - !ruby/object:Gem::Version
33
- version: 1.0.0
33
+ version: 1.2.1
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - ~>
39
39
  - !ruby/object:Gem::Version
40
- version: 1.0.0
40
+ version: 1.2.1
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: simple_uuid
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -59,6 +59,7 @@ executables: []
59
59
  extensions: []
60
60
  extra_rdoc_files: []
61
61
  files:
62
+ - lib/ciql/client/binary.rb
62
63
  - lib/ciql/client/log.rb
63
64
  - lib/ciql/client/thrift.rb
64
65
  - lib/ciql/configuration.rb
@@ -67,6 +68,7 @@ files:
67
68
  - lib/ciql/version.rb
68
69
  - lib/ciql.rb
69
70
  - README.md
71
+ - spec/ciql/client/binary_spec.rb
70
72
  - spec/ciql/client/thrift_spec.rb
71
73
  - spec/ciql/configuration_spec.rb
72
74
  - spec/ciql/sanitize_spec.rb
@@ -96,6 +98,7 @@ signing_key:
96
98
  specification_version: 4
97
99
  summary: CQL Cassandra client for Ruby
98
100
  test_files:
101
+ - spec/ciql/client/binary_spec.rb
99
102
  - spec/ciql/client/thrift_spec.rb
100
103
  - spec/ciql/configuration_spec.rb
101
104
  - spec/ciql/sanitize_spec.rb