cql-rb 1.1.0.rc0 → 1.1.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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MTBkMThlZTE2MTk5MzFiNTgzNmYyMDM4ZTViNjNhNjFhNWM3OGVhNw==
4
+ MjQ0ZjFmMTgzZGI3ZDY1M2RjYTUzZGNmMWE5OTE1NWU5N2U5YWVmNg==
5
5
  data.tar.gz: !binary |-
6
- ZWQ1M2EzZWExOGUyNzUwNzE2ODQxMzgyYmI2MDdkM2ZhY2Q0NTA3OQ==
6
+ Mzk3OWFlMjg3ZTIzODk3OTNjZDcwNDM4OGEyNDI0MGM3MjE2ZTBiNQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- Y2QzMzNmMTg1ODZhYzVmYTU4Njk5MjYzNDgxZmFlMjExZTYwYzRiNjk2MjVj
10
- YmYxOWQ3YzVkNDZlNmM5NWQ2YzYwN2Y5OGMwMDc1NWYzZTBhMzBhZmRlZGU2
11
- ODUwMGY4NGIxNTdlNWVlZThlZTc4M2NhZjU4ODVlMGYyYWM5MWM=
9
+ YjNiMTJlZDg3M2NmNGFlNTllNTZlNTRjZmJjOWEyODYxODFmMWFkOGY5NzBl
10
+ ZTUxOGY1NjNjMzcxMjUwNDA2NjY0N2I0YTk0NWY0OWM5NzBkNzcyNzJkMDI5
11
+ MzljMzNmZWZiYTRhMzMxYWQxMTk0MzVjMzliZjQ3NzVjMzlmY2M=
12
12
  data.tar.gz: !binary |-
13
- YzQ1ZTRjMjUxM2I4OGJlMGRkZDE4NTkwZmZkNWFmZjc5NTNhNWI2ZmNjZTZi
14
- YjE2ZGM0ODIzMDBmNmViNzBjMDU5YzUzZDVkNGNjMTQyMzYzY2FjNDdkYTAx
15
- OGQ4ODIwZDk5YzQ4YjRmOGUxMmYzZTcyNmVlMTcwM2VlNWE5ZjQ=
13
+ MWIxYTk4ZDAwMDA3MDU4MDZmYmU1YmM0YWU5MTUwNmE1ODE5MzI5ZjBlMjA4
14
+ YjI5OWIyN2IxMzRmZjYxMGY4ZmMwZTE5NTk2NDhjM2I2OTg3MWRlYThmOWEy
15
+ ODQzN2VmODFhYjk0OTE1YWUxZWIwYjZjYzUxNTI5YTMxOTRjNTk=
data/README.md CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  # Requirements
7
7
 
8
- Cassandra 1.2 or later with the native transport protocol turned on and a modern Ruby. It's tested continuously in Travis with Ruby 1.9.3, 2.0.0, and JRuby 1.7.x stable and head.
8
+ Cassandra 1.2 or later with the native transport protocol turned on and a modern Ruby. It's tested continuously in Travis with Ruby 1.9.3, 2.0, JRuby 1.7 and Rubinius 2.0.
9
9
 
10
10
  # Installation
11
11
 
@@ -156,6 +156,7 @@ The possible values for consistency are:
156
156
  * `:all`
157
157
  * `:local_quorum`
158
158
  * `:each_quorum`
159
+ * `:local_one`
159
160
 
160
161
  The default consistency level unless you've set it yourself is `:quorum`.
161
162
 
data/lib/cql/protocol.rb CHANGED
@@ -15,7 +15,7 @@ module Cql
15
15
  UnsupportedColumnTypeError = Class.new(ProtocolError)
16
16
  UnsupportedEventTypeError = Class.new(ProtocolError)
17
17
 
18
- CONSISTENCIES = [:any, :one, :two, :three, :quorum, :all, :local_quorum, :each_quorum].freeze
18
+ CONSISTENCIES = [:any, :one, :two, :three, :quorum, :all, :local_quorum, :each_quorum, nil, nil, nil, nil, nil, nil, nil, nil, :local_one].freeze
19
19
 
20
20
  module Formats
21
21
  CHAR_FORMAT = 'c'.freeze
@@ -158,7 +158,7 @@ module Cql
158
158
 
159
159
  def read_consistency!(buffer)
160
160
  index = read_short!(buffer)
161
- raise DecodingError, "Unknown consistency index #{index}" unless index < CONSISTENCIES.size
161
+ raise DecodingError, "Unknown consistency index #{index}" if index >= CONSISTENCIES.size || CONSISTENCIES[index].nil?
162
162
  CONSISTENCIES[index]
163
163
  end
164
164
 
@@ -64,7 +64,7 @@ module Cql
64
64
 
65
65
  def write_consistency(buffer, consistency)
66
66
  index = CONSISTENCIES.index(consistency)
67
- raise EncodingError, %(Unknown consistency "#{consistency}") unless index
67
+ raise EncodingError, %(Unknown consistency "#{consistency}") if index.nil? || CONSISTENCIES[index].nil?
68
68
  write_short(buffer, index)
69
69
  end
70
70
 
@@ -7,7 +7,7 @@ module Cql
7
7
 
8
8
  def initialize(cql, consistency)
9
9
  raise ArgumentError, %(No CQL given!) unless cql
10
- raise ArgumentError, %(No such consistency: #{consistency.inspect}) unless CONSISTENCIES.include?(consistency)
10
+ raise ArgumentError, %(No such consistency: #{consistency.inspect}) if consistency.nil? || !CONSISTENCIES.include?(consistency)
11
11
  super(7)
12
12
  @cql = cql
13
13
  @consistency = consistency
data/lib/cql/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  module Cql
4
- VERSION = '1.1.0.rc0'.freeze
4
+ VERSION = '1.1.0'.freeze
5
5
  end
@@ -470,9 +470,14 @@ module Cql
470
470
  Decoding.read_consistency!(buffer).should == :each_quorum
471
471
  end
472
472
 
473
+ it 'decodes LOCAL_ONE' do
474
+ buffer = ByteBuffer.new("\x00\x10")
475
+ Decoding.read_consistency!(buffer).should == :local_one
476
+ end
477
+
473
478
  it 'raises an exception for an unknown consistency' do
474
- buffer = ByteBuffer.new("\xff\xff")
475
- expect { Decoding.read_consistency!(buffer) }.to raise_error(DecodingError)
479
+ expect { Decoding.read_consistency!(ByteBuffer.new("\xff\xff")) }.to raise_error(DecodingError)
480
+ expect { Decoding.read_consistency!(ByteBuffer.new("\x00\x0a")) }.to raise_error(DecodingError)
476
481
  end
477
482
  end
478
483
 
@@ -237,7 +237,8 @@ module Cql
237
237
  :quorum => "\x00\x04",
238
238
  :all => "\x00\x05",
239
239
  :local_quorum => "\x00\x06",
240
- :each_quorum => "\x00\x07"
240
+ :each_quorum => "\x00\x07",
241
+ :local_one => "\x00\x10",
241
242
  }.each do |consistency, expected_encoding|
242
243
  it "encodes #{consistency}" do
243
244
  Encoding.write_consistency(buffer, consistency)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cql-rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0.rc0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Theo Hultberg
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-10-17 00:00:00.000000000 Z
11
+ date: 2013-10-28 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A pure Ruby CQL3 driver for Cassandra
14
14
  email:
@@ -70,7 +70,6 @@ files:
70
70
  - lib/cql/uuid.rb
71
71
  - lib/cql/version.rb
72
72
  - lib/cql.rb
73
- - bin/cqlexec
74
73
  - README.md
75
74
  - spec/cql/byte_buffer_spec.rb
76
75
  - spec/cql/client/asynchronous_client_spec.rb
@@ -126,9 +125,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
126
125
  version: 1.9.2
127
126
  required_rubygems_version: !ruby/object:Gem::Requirement
128
127
  requirements:
129
- - - ! '>'
128
+ - - ! '>='
130
129
  - !ruby/object:Gem::Version
131
- version: 1.3.1
130
+ version: '0'
132
131
  requirements: []
133
132
  rubyforge_project:
134
133
  rubygems_version: 2.1.5
data/bin/cqlexec DELETED
@@ -1,135 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # encoding: utf-8
3
-
4
- $: << File.expand_path('../../lib', __FILE__)
5
-
6
- require 'optparse'
7
- require 'set'
8
- require 'cql'
9
-
10
-
11
- class CqlExecutor
12
- def initialize(args)
13
- @options = parse_options!(args)
14
- end
15
-
16
- def run(io)
17
- @client = Cql::Client.connect(host: @options[:host], port: @options[:port])
18
-
19
- # TODO register for events
20
-
21
- begin
22
- buffer = ''
23
- while (line = io.gets)
24
- buffer << line
25
- if semi_index = buffer.index(';')
26
- query = buffer.slice!(0, semi_index + 1)
27
- prepare_and_execute_request(query)
28
- end
29
- end
30
- prepare_and_execute_request(buffer)
31
- rescue Cql::CqlError => e
32
- abort("Error: #{e.message} (#{e.class})")
33
- rescue Interrupt
34
- exit
35
- ensure
36
- @client.close
37
- end
38
- end
39
-
40
- private
41
-
42
- def parse_options!(args)
43
- options = {}
44
-
45
- option_parser = OptionParser.new do |opts|
46
- opts.banner = "Usage: #{File.basename(__FILE__)} [options]"
47
- opts.separator('')
48
- opts.on('--help', 'Show this message') do
49
- $stderr.puts(opts)
50
- exit!
51
- end
52
- opts.on('-h', '--host [HOST]', 'Connect to HOST, defaults to localhost') do |host|
53
- options[:host] = host
54
- end
55
- opts.on('-p', '--port [PORT]', Integer, 'Connect to PORT, defaults to 9042') do |port|
56
- options[:port] = port
57
- end
58
- opts.on('-v', '--verbose', 'Print requests to STDERR') do |port|
59
- options[:verbose] = true
60
- end
61
- opts.separator('')
62
- opts.separator('Pass CQL commands on STDIN, prints results on STDOUT')
63
- opts.separator('')
64
- end
65
-
66
- option_parser.parse!
67
-
68
- options
69
- end
70
-
71
- def prepare_and_execute_request(query)
72
- query.chomp!(';')
73
- query.strip!
74
- unless query.empty?
75
- format_table_output(@client.execute(query, :one))
76
- end
77
- end
78
-
79
- def format_table_output(rows)
80
- table_names = []
81
- header = ''
82
- row_format = ''
83
- divider = ''
84
- column_widths = {}
85
- if rows && rows.any?
86
- rows.metadata.each do |ks, table, column, type|
87
- table_names << [ks, table].join('.')
88
- column_width = [format_value(rows.first[column]).length, column.length].max
89
- column_widths[column] = column_width
90
- format = "%-#{column_width}.#{column_width}s"
91
- header << "#{format} | " % [column]
92
- row_format << "#{format} | "
93
- divider << ('-' * column_width) << '-+-'
94
- end
95
- row_format.sub!(/ \| $/, '')
96
- divider = divider[0..-4]
97
- table_name = table_names.uniq.join(', ')
98
-
99
- $stdout.puts(table_name)
100
- $stdout.puts('=' * table_name.length)
101
- $stdout.puts(header[0, divider.length])
102
- $stdout.puts(divider)
103
-
104
- rows.each do |row|
105
- values = rows.metadata.map do |_, _, column, _|
106
- limit_width(format_value(row[column]), column_widths[column])
107
- end
108
- $stdout.puts(row_format % values)
109
- end
110
- else
111
- $stdout.puts('(empty result set)')
112
- end
113
- end
114
-
115
- def format_value(value)
116
- case value
117
- when Set
118
- value.to_a.to_s
119
- when nil
120
- '(nil)'
121
- else
122
- value.to_s
123
- end
124
- end
125
-
126
- def limit_width(value, width)
127
- if value.length > width
128
- value[0, width - 1] << '…'
129
- else
130
- value
131
- end
132
- end
133
- end
134
-
135
- CqlExecutor.new(ARGV).run(STDIN)