cassanity 0.3.0 → 0.4.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.
Files changed (66) hide show
  1. data/Changelog.md +10 -0
  2. data/Gemfile +5 -3
  3. data/README.md +22 -15
  4. data/examples/_shared.rb +5 -1
  5. data/examples/batch.rb +17 -23
  6. data/examples/column_families.rb +12 -13
  7. data/examples/counters.rb +10 -18
  8. data/examples/keyspaces.rb +12 -17
  9. data/examples/select_range.rb +29 -19
  10. data/lib/cassanity/argument_generators/batch.rb +8 -0
  11. data/lib/cassanity/argument_generators/column_family_alter.rb +1 -1
  12. data/lib/cassanity/argument_generators/column_family_create.rb +1 -1
  13. data/lib/cassanity/argument_generators/column_family_delete.rb +2 -22
  14. data/lib/cassanity/argument_generators/column_family_drop.rb +1 -1
  15. data/lib/cassanity/argument_generators/column_family_insert.rb +2 -24
  16. data/lib/cassanity/argument_generators/column_family_select.rb +1 -1
  17. data/lib/cassanity/argument_generators/column_family_truncate.rb +1 -1
  18. data/lib/cassanity/argument_generators/column_family_update.rb +2 -24
  19. data/lib/cassanity/argument_generators/keyspace_create.rb +1 -1
  20. data/lib/cassanity/argument_generators/keyspace_drop.rb +1 -1
  21. data/lib/cassanity/argument_generators/keyspace_use.rb +1 -1
  22. data/lib/cassanity/argument_generators/where_clause.rb +1 -0
  23. data/lib/cassanity/argument_generators/with_clause.rb +12 -6
  24. data/lib/cassanity/client.rb +65 -0
  25. data/lib/cassanity/column_family.rb +70 -17
  26. data/lib/cassanity/connection.rb +8 -0
  27. data/lib/cassanity/decrement.rb +2 -15
  28. data/lib/cassanity/executors/cassandra_cql.rb +37 -11
  29. data/lib/cassanity/increment.rb +2 -15
  30. data/lib/cassanity/instrumentation/log_subscriber.rb +27 -0
  31. data/lib/cassanity/instrumenters/memory.rb +27 -0
  32. data/lib/cassanity/instrumenters/noop.rb +9 -0
  33. data/lib/cassanity/keyspace.rb +42 -6
  34. data/lib/cassanity/operator.rb +9 -0
  35. data/lib/cassanity/range.rb +4 -0
  36. data/lib/cassanity/schema.rb +21 -0
  37. data/lib/cassanity/version.rb +1 -1
  38. data/lib/cassanity.rb +16 -2
  39. data/spec/integration/cassanity/column_family_spec.rb +59 -78
  40. data/spec/integration/cassanity/connection_spec.rb +18 -34
  41. data/spec/integration/cassanity/keyspace_spec.rb +24 -34
  42. data/spec/unit/cassanity/argument_generators/batch_spec.rb +51 -3
  43. data/spec/unit/cassanity/argument_generators/column_family_alter_spec.rb +6 -6
  44. data/spec/unit/cassanity/argument_generators/column_family_create_spec.rb +6 -6
  45. data/spec/unit/cassanity/argument_generators/column_family_delete_spec.rb +5 -5
  46. data/spec/unit/cassanity/argument_generators/column_family_drop_spec.rb +2 -2
  47. data/spec/unit/cassanity/argument_generators/column_family_insert_spec.rb +5 -5
  48. data/spec/unit/cassanity/argument_generators/column_family_select_spec.rb +12 -12
  49. data/spec/unit/cassanity/argument_generators/column_family_truncate_spec.rb +2 -2
  50. data/spec/unit/cassanity/argument_generators/column_family_update_spec.rb +5 -5
  51. data/spec/unit/cassanity/argument_generators/keyspace_create_spec.rb +4 -4
  52. data/spec/unit/cassanity/argument_generators/keyspace_drop_spec.rb +1 -1
  53. data/spec/unit/cassanity/argument_generators/keyspace_use_spec.rb +1 -1
  54. data/spec/unit/cassanity/argument_generators/where_clause_spec.rb +26 -0
  55. data/spec/unit/cassanity/argument_generators/with_clause_spec.rb +26 -0
  56. data/spec/unit/cassanity/client_spec.rb +159 -0
  57. data/spec/unit/cassanity/column_family_spec.rb +64 -17
  58. data/spec/unit/cassanity/connection_spec.rb +8 -0
  59. data/spec/unit/cassanity/executors/cassandra_cql_spec.rb +35 -19
  60. data/spec/unit/cassanity/instrumentors/memory_spec.rb +26 -0
  61. data/spec/unit/cassanity/instrumentors/noop_spec.rb +22 -0
  62. data/spec/unit/cassanity/keyspace_spec.rb +25 -3
  63. data/spec/unit/cassanity/operator_spec.rb +10 -0
  64. data/spec/unit/cassanity/schema_spec.rb +6 -0
  65. data/spec/unit/cassanity_spec.rb +6 -0
  66. metadata +15 -4
@@ -27,7 +27,13 @@ module Cassanity
27
27
  @name = args.fetch(:name)
28
28
  @keyspace = args.fetch(:keyspace)
29
29
  @executor = args.fetch(:executor) { @keyspace.executor }
30
- @schema = args[:schema]
30
+
31
+ schema = args[:schema]
32
+ @schema = if schema.is_a?(Hash)
33
+ Cassanity::Schema.new(schema)
34
+ else
35
+ schema
36
+ end
31
37
  end
32
38
 
33
39
  # Public: Returns true or false depending on if column family exists in
@@ -56,7 +62,7 @@ module Cassanity
56
62
  # Public: Creates the column family in the keyspace based on the schema.
57
63
  #
58
64
  # args - The Hash of arguments to pass to the executor. Always passes
59
- # :name and :keyspace_name.
65
+ # :column_family_name and :keyspace_name.
60
66
  # :schema - The Schema to use to create the column family
61
67
  # (defaults to schema provided during initialization).
62
68
  #
@@ -70,7 +76,7 @@ module Cassanity
70
76
  # not passed in via arguments.
71
77
  def create(args = {})
72
78
  forced_arguments = {
73
- name: @name,
79
+ column_family_name: @name,
74
80
  keyspace_name: @keyspace.name,
75
81
  }
76
82
  arguments = args.merge(forced_arguments)
@@ -85,7 +91,8 @@ module Cassanity
85
91
  # Public: Truncates the column family.
86
92
  #
87
93
  # args - The Hash of arguments to pass to the argument generator
88
- # (default: {}). :name and :keyspace_name are always included.
94
+ # (default: {}). :column_family_name and :keyspace_name are
95
+ # always included.
89
96
  #
90
97
  # Examples
91
98
  #
@@ -96,7 +103,7 @@ module Cassanity
96
103
  @executor.call({
97
104
  command: :column_family_truncate,
98
105
  arguments: args.merge({
99
- name: @name,
106
+ column_family_name: @name,
100
107
  keyspace_name: @keyspace.name,
101
108
  }),
102
109
  })
@@ -105,7 +112,8 @@ module Cassanity
105
112
  # Public: Drops the column family.
106
113
  #
107
114
  # args - The Hash of arguments to pass to the argument generator
108
- # (default: {}). :name and :keyspace_name are always included.
115
+ # (default: {}). :column_family_name and :keyspace_name are
116
+ # always included.
109
117
  #
110
118
  # Examples
111
119
  #
@@ -116,7 +124,7 @@ module Cassanity
116
124
  @executor.call({
117
125
  command: :column_family_drop,
118
126
  arguments: args.merge({
119
- name: @name,
127
+ column_family_name: @name,
120
128
  keyspace_name: @keyspace.name,
121
129
  }),
122
130
  })
@@ -125,7 +133,8 @@ module Cassanity
125
133
  # Public: Alters the column family.
126
134
  #
127
135
  # args - The Hash of arguments to pass to the argument generator
128
- # (default: {}). :name and :keyspace_name are always included.
136
+ # (default: {}). :column_family_name and :keyspace_name are
137
+ # always included.
129
138
  #
130
139
  # Examples
131
140
  #
@@ -139,7 +148,7 @@ module Cassanity
139
148
  @executor.call({
140
149
  command: :column_family_alter,
141
150
  arguments: args.merge({
142
- name: @name,
151
+ column_family_name: @name,
143
152
  keyspace_name: @keyspace.name,
144
153
  }),
145
154
  })
@@ -187,14 +196,15 @@ module Cassanity
187
196
  # Public: Makes it possible to query data from the column family.
188
197
  #
189
198
  # args - The Hash of arguments to pass to the argument generator
190
- # (default: {}). :name and :keyspace_name are always included.
199
+ # (default: {}). :column_family_name and :keyspace_name are
200
+ # always included.
191
201
  #
192
202
  # Returns whatever is returned by executor.
193
203
  def select(args = {})
194
204
  @executor.call({
195
205
  command: :column_family_select,
196
206
  arguments: args.merge({
197
- name: @name,
207
+ column_family_name: @name,
198
208
  keyspace_name: @keyspace.name,
199
209
  })
200
210
  })
@@ -203,14 +213,15 @@ module Cassanity
203
213
  # Public: Makes it possible to insert data into the column family.
204
214
  #
205
215
  # args - The Hash of arguments to pass to the argument generator
206
- # (default: {}). :name and :keyspace_name are always included.
216
+ # (default: {}). :column_family_name and :keyspace_name are
217
+ # always included.
207
218
  #
208
219
  # Returns whatever is returned by executor.
209
220
  def insert(args = {})
210
221
  @executor.call({
211
222
  command: :column_family_insert,
212
223
  arguments: args.merge({
213
- name: @name,
224
+ column_family_name: @name,
214
225
  keyspace_name: @keyspace.name,
215
226
  }),
216
227
  })
@@ -219,14 +230,15 @@ module Cassanity
219
230
  # Public: Makes it possible to update data in the column family.
220
231
  #
221
232
  # args - The Hash of arguments to pass to the argument generator
222
- # (default: {}). :name and :keyspace_name are always included.
233
+ # (default: {}). :column_family_name and :keyspace_name are
234
+ # always included.
223
235
  #
224
236
  # Returns whatever is returned by executor.
225
237
  def update(args = {})
226
238
  @executor.call({
227
239
  command: :column_family_update,
228
240
  arguments: args.merge({
229
- name: @name,
241
+ column_family_name: @name,
230
242
  keyspace_name: @keyspace.name,
231
243
  }),
232
244
  })
@@ -235,22 +247,63 @@ module Cassanity
235
247
  # Public: Makes it possible to delete data from the column family.
236
248
  #
237
249
  # args - The Hash of arguments to pass to the argument generator
238
- # (default: {}). :name and :keyspace_name are always included.
250
+ # (default: {}). :column_family_name and :keyspace_name are
251
+ # always included.
239
252
  #
240
253
  # Returns whatever is returned by executor.
241
254
  def delete(args = {})
242
255
  @executor.call({
243
256
  command: :column_family_delete,
244
257
  arguments: args.merge({
245
- name: @name,
258
+ column_family_name: @name,
246
259
  keyspace_name: @keyspace.name,
247
260
  }),
248
261
  })
249
262
  end
250
263
 
264
+ # Public: Group multiple statements into a batch.
265
+ #
266
+ # args - The Hash of arguments to pass to the argument generator
267
+ # (default: {}).
268
+ #
269
+ # Examples
270
+ #
271
+ # batch({
272
+ # modifications: [
273
+ # [:insert, column_family_name: 'apps', data: {id: '1', name: 'github'}],
274
+ # [:insert, column_family_name: 'apps', data: {id: '2', name: 'gist'}],
275
+ # [:update, column_family_name: 'apps', set: {name: 'github.com'}, where: {id: '1'}],
276
+ # [:delete, column_family_name: 'apps', where: {id: '2'}],
277
+ # ]
278
+ # })
279
+ #
280
+ # Returns whatever is returned by executor.
281
+ def batch(args = {})
282
+ default_arguments = {
283
+ keyspace_name: @keyspace.name,
284
+ column_family_name: @name,
285
+ }
286
+
287
+ @executor.call({
288
+ command: :batch,
289
+ arguments: default_arguments.merge(args),
290
+ })
291
+ end
292
+
251
293
  # Internal
252
294
  def schema
253
295
  @schema || raise(Cassanity::Error.new(message: "No schema found to create #{@name} column family. Please set :schema during initialization or include it as a key in #create call."))
254
296
  end
297
+
298
+ # Public
299
+ def inspect
300
+ attributes = [
301
+ "name=#{@name.inspect}",
302
+ "keyspace=#{@keyspace.inspect}",
303
+ "executor=#{@executor.inspect}",
304
+ "schema=#{@schema.inspect}",
305
+ ]
306
+ "#<#{self.class.name}:#{object_id} #{attributes.join(', ')}>"
307
+ end
255
308
  end
256
309
  end
@@ -73,5 +73,13 @@ module Cassanity
73
73
  end
74
74
 
75
75
  alias_method :[], :keyspace
76
+
77
+ # Public
78
+ def inspect
79
+ attributes = [
80
+ "executor=#{@executor.inspect}",
81
+ ]
82
+ "#<#{self.class.name}:#{object_id} #{attributes.join(', ')}>"
83
+ end
76
84
  end
77
85
  end
@@ -3,25 +3,12 @@ module Cassanity
3
3
  Decrement.new(*args)
4
4
  end
5
5
 
6
- class Decrement
7
- # Internal
8
- attr_reader :symbol
9
-
10
- # Internal
11
- attr_reader :value
12
-
6
+ class Decrement < Operator
13
7
  # Public: Returns an decrement instance
14
8
  def initialize(value = 1)
15
9
  raise ArgumentError.new("value cannot be nil") if value.nil?
16
10
 
17
- @symbol = :-
18
- @value = value
11
+ super :-, value
19
12
  end
20
-
21
- def eql?(other)
22
- self.class.eql?(other.class) && value == other.value
23
- end
24
-
25
- alias_method :==, :eql?
26
13
  end
27
14
  end
@@ -1,5 +1,7 @@
1
+ require 'forwardable'
1
2
  require 'cassandra-cql'
2
3
  require 'cassanity/error'
4
+ require 'cassanity/instrumenters/noop'
3
5
  require 'cassanity/argument_generators/keyspaces'
4
6
  require 'cassanity/argument_generators/keyspace_create'
5
7
  require 'cassanity/argument_generators/keyspace_drop'
@@ -22,6 +24,7 @@ require 'cassanity/result_transformers/mirror'
22
24
  module Cassanity
23
25
  module Executors
24
26
  class CassandraCql
27
+ extend Forwardable
25
28
 
26
29
  # Private: Hash of commands to related argument generators.
27
30
  ArgumentGenerators = {
@@ -53,6 +56,9 @@ module Cassanity
53
56
  # Private: Default result transformer for commands that do not have one.
54
57
  Mirror = Cassanity::ResultTransformers::Mirror.new
55
58
 
59
+ # Private: Forward #instrument to instrumenter.
60
+ def_delegator :@instrumenter, :instrument
61
+
56
62
  # Private
57
63
  attr_reader :client
58
64
 
@@ -62,11 +68,15 @@ module Cassanity
62
68
  # Private
63
69
  attr_reader :result_transformers
64
70
 
71
+ # Private: What should be used to instrument all the things.
72
+ attr_reader :instrumenter
73
+
65
74
  # Internal: Initializes a cassandra-cql based CQL executor.
66
75
  #
67
76
  # args - The Hash of arguments.
68
77
  # :client - The CassandraCQL::Database connection instance.
69
- # :logger - What to use to log the cql and such being executed.
78
+ # :instrumenter - What should be used to instrument all the things
79
+ # (default: Cassanity::Instrumenters::Noop).
70
80
  # :argument_generators - A Hash where each key is a command name
71
81
  # and each value is the related argument
72
82
  # generator that responds to `call`
@@ -83,7 +93,7 @@ module Cassanity
83
93
  #
84
94
  def initialize(args = {})
85
95
  @client = args.fetch(:client)
86
- @logger = args[:logger]
96
+ @instrumenter = args[:instrumenter] || Instrumenters::Noop
87
97
  @argument_generators = args.fetch(:argument_generators) { ArgumentGenerators }
88
98
  @result_transformers = args.fetch(:result_transformers) { ResultTransformers }
89
99
  end
@@ -108,23 +118,39 @@ module Cassanity
108
118
  # Returns the result of execution.
109
119
  # Raises Cassanity::Error if anything goes wrong during execution.
110
120
  def call(args = {})
111
- command = args.fetch(:command)
112
- generator = @argument_generators.fetch(command)
113
- execute_arguments = generator.call(args[:arguments])
121
+ instrument('cql.cassanity', {}) do |payload|
122
+ command = args.fetch(:command)
123
+ generator = @argument_generators.fetch(command)
124
+ arguments = args[:arguments]
125
+ execute_arguments = generator.call(arguments)
114
126
 
115
- if @logger
116
- @logger.debug { "#{self.class} executing #{execute_arguments.inspect}" }
117
- end
127
+ result = @client.execute(*execute_arguments)
128
+
129
+ transformer = @result_transformers.fetch(command) { Mirror }
130
+ transformed_result = transformer.call(result)
118
131
 
119
- result = @client.execute(*execute_arguments)
132
+ payload[:command] = command
133
+ payload[:generator] = generator
134
+ payload[:arguments] = arguments
135
+ payload[:execute_arguments] = execute_arguments
136
+ payload[:result] = result
137
+ payload[:transformer] = transformer
120
138
 
121
- transformer = @result_transformers.fetch(command) { Mirror }
122
- transformer.call(result)
139
+ transformed_result
140
+ end
123
141
  rescue KeyError
124
142
  raise Cassanity::UnknownCommand
125
143
  rescue Exception => e
126
144
  raise Cassanity::Error
127
145
  end
146
+
147
+ # Public
148
+ def inspect
149
+ attributes = [
150
+ "client=#{@client.inspect}",
151
+ ]
152
+ "#<#{self.class.name}:#{object_id} #{attributes.join(', ')}>"
153
+ end
128
154
  end
129
155
  end
130
156
  end
@@ -3,25 +3,12 @@ module Cassanity
3
3
  Increment.new(*args)
4
4
  end
5
5
 
6
- class Increment
7
- # Internal
8
- attr_reader :symbol
9
-
10
- # Internal
11
- attr_reader :value
12
-
6
+ class Increment < Operator
13
7
  # Public: Returns an increment instance
14
8
  def initialize(value = 1)
15
9
  raise ArgumentError.new("value cannot be nil") if value.nil?
16
10
 
17
- @symbol = :+
18
- @value = value
11
+ super :+, value
19
12
  end
20
-
21
- def eql?(other)
22
- self.class.eql?(other.class) && value == other.value
23
- end
24
-
25
- alias_method :==, :eql?
26
13
  end
27
14
  end
@@ -0,0 +1,27 @@
1
+ require 'securerandom'
2
+ require 'active_support/notifications'
3
+ require 'active_support/log_subscriber'
4
+
5
+ module Cassanity
6
+ module Instrumentation
7
+ class LogSubscriber < ::ActiveSupport::LogSubscriber
8
+ def cql(event)
9
+ return unless logger.debug?
10
+
11
+ name = '%s (%.1fms)' % ["CQL Query", event.duration]
12
+
13
+ # execute arguments are always an array where the first element is the
14
+ # cql string and the rest are the bound variables.
15
+ cql, *args = event.payload[:execute_arguments]
16
+ arguments = args.map { |arg| arg.inspect }.join(', ')
17
+
18
+ query = "#{cql}"
19
+ query += " (#{arguments})" unless arguments.empty?
20
+
21
+ debug " #{color(name, CYAN, true)} [ #{query} ]"
22
+ end
23
+ end
24
+ end
25
+ end
26
+
27
+ Cassanity::Instrumentation::LogSubscriber.attach_to :cassanity
@@ -0,0 +1,27 @@
1
+ module Cassanity
2
+ module Instrumenters
3
+ # Instrumentor that is useful for tests as it stores each of the events that
4
+ # are instrumented.
5
+ class Memory
6
+ Event = Struct.new(:name, :payload, :result)
7
+
8
+ attr_reader :events
9
+
10
+ def initialize
11
+ @events = []
12
+ end
13
+
14
+ def instrument(name, payload = {})
15
+ result = if block_given?
16
+ yield payload
17
+ else
18
+ nil
19
+ end
20
+
21
+ @events << Event.new(name, payload, result)
22
+
23
+ result
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,9 @@
1
+ module Cassanity
2
+ module Instrumenters
3
+ class Noop
4
+ def self.instrument(name, payload = {})
5
+ yield payload if block_given?
6
+ end
7
+ end
8
+ end
9
+ end
@@ -45,7 +45,7 @@ module Cassanity
45
45
  # Public: Creates the keyspace
46
46
  #
47
47
  # args - The Hash of arguments to pass to the argument generator
48
- # (default: {}). :name is always included.
48
+ # (default: {}). :keyspace_name is always included.
49
49
  #
50
50
  # Examples
51
51
  #
@@ -65,7 +65,7 @@ module Cassanity
65
65
  @executor.call({
66
66
  command: :keyspace_create,
67
67
  arguments: args.merge({
68
- name: @name,
68
+ keyspace_name: @name,
69
69
  })
70
70
  })
71
71
  end
@@ -81,7 +81,7 @@ module Cassanity
81
81
  # Public: Uses a keyspace
82
82
  #
83
83
  # args - The Hash of arguments to pass to the argument generator
84
- # (default: {}). :name is always included.
84
+ # (default: {}). :keyspace_name is always included.
85
85
  #
86
86
  # Examples
87
87
  #
@@ -92,7 +92,7 @@ module Cassanity
92
92
  @executor.call({
93
93
  command: :keyspace_use,
94
94
  arguments: args.merge({
95
- name: @name,
95
+ keyspace_name: @name,
96
96
  }),
97
97
  })
98
98
  end
@@ -100,7 +100,7 @@ module Cassanity
100
100
  # Public: Drops a keyspace
101
101
  #
102
102
  # args - The Hash of arguments to pass to the argument generator
103
- # (default: {}). :name is always included.
103
+ # (default: {}). :keyspace_name is always included.
104
104
  #
105
105
  # Examples
106
106
  #
@@ -111,7 +111,7 @@ module Cassanity
111
111
  @executor.call({
112
112
  command: :keyspace_drop,
113
113
  arguments: args.merge({
114
- name: @name,
114
+ keyspace_name: @name,
115
115
  }),
116
116
  })
117
117
  end
@@ -152,5 +152,41 @@ module Cassanity
152
152
  end
153
153
  alias_method :table, :column_family
154
154
  alias_method :[], :column_family
155
+
156
+ # Public: Group multiple statements into a batch.
157
+ #
158
+ # args - The Hash of arguments to pass to the argument generator
159
+ # (default: {}).
160
+ #
161
+ # Examples
162
+ #
163
+ # batch({
164
+ # modifications: [
165
+ # [:insert, name: 'apps', data: {id: '1', name: 'github'}],
166
+ # [:insert, name: 'apps', data: {id: '2', name: 'gist'}],
167
+ # [:update, name: 'apps', set: {name: 'github.com'}, where: {id: '1'}],
168
+ # [:delete, name: 'apps', where: {id: '2'}],
169
+ # ]
170
+ # })
171
+ #
172
+ # Returns whatever is returned by executor.
173
+ def batch(args = {})
174
+ default_arguments = {
175
+ keyspace_name: @name,
176
+ }
177
+
178
+ @executor.call({
179
+ command: :batch,
180
+ arguments: default_arguments.merge(args),
181
+ })
182
+ end
183
+
184
+ # Public
185
+ def inspect
186
+ attributes = [
187
+ "name=#{@name.inspect}",
188
+ ]
189
+ "#<#{self.class.name}:#{object_id} #{attributes.join(', ')}>"
190
+ end
155
191
  end
156
192
  end
@@ -23,5 +23,14 @@ module Cassanity
23
23
  end
24
24
 
25
25
  alias_method :==, :eql?
26
+
27
+ # Public
28
+ def inspect
29
+ attributes = [
30
+ "symbol=#{symbol.inspect}",
31
+ "value=#{value.inspect}",
32
+ ]
33
+ "#<#{self.class.name}:#{object_id} #{attributes.join(', ')}>"
34
+ end
26
35
  end
27
36
  end
@@ -0,0 +1,4 @@
1
+ module Cassanity
2
+ # For now, cassanity's range can just be a core range.
3
+ Range = ::Range
4
+ end
@@ -20,6 +20,7 @@ module Cassanity
20
20
  # :columns - The Hash of columns where the name is the column name
21
21
  # and the value is the column type.
22
22
  # :with - The Hash of options for the WITH clause.
23
+ #
23
24
  # Raises KeyError if missing required argument key.
24
25
  # Raises ArgumentError if primary key is not included in the columns.
25
26
  def initialize(args = {})
@@ -59,5 +60,25 @@ module Cassanity
59
60
  shared_columns = column_names & @primary_keys
60
61
  shared_columns == @primary_keys
61
62
  end
63
+
64
+ # Public
65
+ def inspect
66
+ attributes = [
67
+ "primary_keys=#{primary_keys.inspect}",
68
+ "columns=#{columns.inspect}",
69
+ "with=#{with.inspect}",
70
+ ]
71
+ "#<#{self.class.name}:#{object_id} #{attributes.join(', ')}>"
72
+ end
73
+
74
+ # Public: Is this schema equal to another object.
75
+ def eql?(other)
76
+ self.class.eql?(other.class) &&
77
+ @primary_keys == other.primary_keys &&
78
+ @columns == other.columns &&
79
+ @with == other.with
80
+ end
81
+
82
+ alias_method :==, :eql?
62
83
  end
63
84
  end
@@ -1,3 +1,3 @@
1
1
  module Cassanity
2
- VERSION = "0.3.0"
2
+ VERSION = "0.4.0"
3
3
  end
data/lib/cassanity.rb CHANGED
@@ -3,6 +3,9 @@ require 'cassanity/operators/gt'
3
3
  require 'cassanity/operators/gte'
4
4
  require 'cassanity/operators/lt'
5
5
  require 'cassanity/operators/lte'
6
+ require 'cassanity/increment'
7
+ require 'cassanity/decrement'
8
+ require 'cassanity/range'
6
9
 
7
10
  module Cassanity
8
11
  # Public: Shortcut for returning an equality operator.
@@ -68,6 +71,18 @@ module Cassanity
68
71
  Decrement.new(value)
69
72
  end
70
73
 
74
+ # Public: Shortcut for returning a range value.
75
+ #
76
+ # start - The start value for the range.
77
+ # finish - The finish value for the range.
78
+ # exclusive - The Boolean value for whether or not to include the finish of
79
+ # the range.
80
+ #
81
+ # Returns a Cassanity::Range instance.
82
+ def self.range(start, finish, exclusive = false)
83
+ Cassanity::Range.new(start, finish, exclusive)
84
+ end
85
+
71
86
  class << self
72
87
  alias_method :equal, :eq
73
88
 
@@ -85,5 +100,4 @@ module Cassanity
85
100
  end
86
101
  end
87
102
 
88
- require 'cassanity/connection'
89
- require 'cassanity/executors/cassandra_cql'
103
+ require 'cassanity/client'