ciql 0.2.4 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/ciql/client/binary.rb +48 -0
- data/lib/ciql/client/thrift.rb +9 -7
- data/lib/ciql/configuration.rb +1 -1
- data/lib/ciql/version.rb +1 -1
- data/lib/ciql.rb +1 -1
- data/spec/ciql/client/binary_spec.rb +30 -0
- data/spec/ciql/client/thrift_spec.rb +2 -1
- metadata +13 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5e9c50f26c2571d06b20a0af39bf3ab2ecccf4c2
|
4
|
+
data.tar.gz: a5d0b7fa17071fb32f1149de13480c24386bb854
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
data/lib/ciql/client/thrift.rb
CHANGED
@@ -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
|
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
|
24
|
-
bound_statement
|
25
|
-
compression_type
|
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
|
data/lib/ciql/configuration.rb
CHANGED
data/lib/ciql/version.rb
CHANGED
data/lib/ciql.rb
CHANGED
@@ -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
|
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.
|
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-
|
11
|
+
date: 2013-12-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: cql-rb
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ~>
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
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:
|
26
|
+
version: 1.1.1
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name: cql
|
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.
|
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.
|
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
|