cequel 0.5.5 → 0.5.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -294,6 +294,9 @@ module Cequel
294
294
  # @option options [Time,Integer] :timestamp the timestamp associated with the column values
295
295
  #
296
296
  def generate_upsert_options(options)
297
+ if keyspace.default_consistency
298
+ options[:consistency] ||= keyspace.default_consistency
299
+ end
297
300
  if options.empty?
298
301
  ''
299
302
  else
@@ -331,8 +334,9 @@ module Cequel
331
334
  end
332
335
 
333
336
  def consistency_cql
334
- if @consistency
335
- " USING CONSISTENCY #{@consistency.upcase}"
337
+ consistency = @consistency || keyspace.default_consistency
338
+ if consistency
339
+ " USING CONSISTENCY #{consistency.upcase}"
336
340
  else ''
337
341
  end
338
342
  end
@@ -50,6 +50,22 @@ module Cequel
50
50
  @slowlog_threshold
51
51
  end
52
52
 
53
+ def with_consistency(consistency)
54
+ previous_consistency = default_consistency
55
+ Thread.current[consistency_key] = consistency
56
+ yield
57
+ ensure
58
+ Thread.current[consistency_key] = previous_consistency
59
+ end
60
+
61
+ def default_consistency
62
+ Thread.current[consistency_key]
63
+ end
64
+
65
+ def consistency_key
66
+ "Cequel::Keyspace[#{object_id}]#default_consistency"
67
+ end
68
+
53
69
  def connection_pool
54
70
  return @connection_pool if defined? @connection_pool
55
71
  if @configuration[:pool]
@@ -49,6 +49,10 @@ module Cequel
49
49
  Cequel::Model.keyspace
50
50
  end
51
51
 
52
+ def with_consistency(consistency, &block)
53
+ keyspace.with_consistency(consistency, &block)
54
+ end
55
+
52
56
  def _hydrate(row)
53
57
  type_column_name = @_cequel.type_column.try(:name)
54
58
  if type_column_name && row[type_column_name]
@@ -1,3 +1,3 @@
1
1
  module Cequel
2
- VERSION = '0.5.5'
2
+ VERSION = '0.5.6'
3
3
  end
@@ -19,6 +19,15 @@ describe Cequel::DataSet do
19
19
  )
20
20
  end
21
21
 
22
+ it 'should respect with_consistency block' do
23
+ connection.should_receive(:execute).
24
+ with "INSERT INTO posts (?) VALUES (?) USING CONSISTENCY QUORUM", [:id, :title], [1, 'Fun times']
25
+
26
+ cequel.with_consistency(:quorum) do
27
+ cequel[:posts].insert(:id => 1, :title => 'Fun times')
28
+ end
29
+ end
30
+
22
31
  it 'should include ttl argument' do
23
32
  connection.should_receive(:execute).
24
33
  with "INSERT INTO posts (?) VALUES (?) USING TTL 600", [:id, :title], [1, 'Fun times']
@@ -75,6 +84,15 @@ describe Cequel::DataSet do
75
84
  )
76
85
  end
77
86
 
87
+ it 'should respect default consistency' do
88
+ connection.should_receive(:execute).
89
+ with "UPDATE posts USING CONSISTENCY QUORUM SET ? = ?, ? = ?", :title, 'Fun times', :body, 'Fun'
90
+
91
+ cequel.with_consistency(:quorum) do
92
+ cequel[:posts].update(:title => 'Fun times', :body => 'Fun')
93
+ end
94
+ end
95
+
78
96
  it 'should send update statement scoped to current row specifications' do
79
97
  connection.should_receive(:execute).
80
98
  with "UPDATE posts SET ? = ? WHERE ? = ?", :title, 'Fun', :id, 4
@@ -146,6 +164,15 @@ describe Cequel::DataSet do
146
164
  )
147
165
  end
148
166
 
167
+ it 'should respect default consistency' do
168
+ connection.should_receive(:execute).
169
+ with "DELETE ? FROM posts USING CONSISTENCY QUORUM", [:title, :body]
170
+
171
+ cequel.with_consistency(:quorum) do
172
+ cequel[:posts].delete(:title, :body)
173
+ end
174
+ end
175
+
149
176
  it 'should send delete statement with scoped row specifications' do
150
177
  connection.should_receive(:execute).
151
178
  with "DELETE FROM posts WHERE ? = ?", :id, 4
@@ -310,6 +337,15 @@ describe Cequel::DataSet do
310
337
  end
311
338
  end
312
339
 
340
+ describe 'in with_consistency block' do
341
+ it 'should use default consistency' do
342
+ cequel.with_consistency(:quorum) do
343
+ cequel[:posts].cql.
344
+ should == ["SELECT * FROM posts USING CONSISTENCY QUORUM"]
345
+ end
346
+ end
347
+ end
348
+
313
349
  describe '#limit' do
314
350
  it 'should add LIMIT' do
315
351
  cequel[:posts].limit(2).cql.
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cequel
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.5
4
+ version: 0.5.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2013-04-17 00:00:00.000000000 Z
14
+ date: 2013-04-29 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: activesupport
@@ -171,80 +171,80 @@ extensions: []
171
171
  extra_rdoc_files: []
172
172
  files:
173
173
  - lib/cequel.rb
174
+ - lib/cequel/keyspace.rb
174
175
  - lib/cequel/cql_row_specification.rb
175
- - lib/cequel/statement.rb
176
176
  - lib/cequel/model/inheritable.rb
177
- - lib/cequel/model/remote_association.rb
178
177
  - lib/cequel/model/counter.rb
179
- - lib/cequel/model/naming.rb
180
- - lib/cequel/model/readable_dictionary.rb
181
- - lib/cequel/model/associations.rb
182
- - lib/cequel/model/mass_assignment_security.rb
183
- - lib/cequel/model/dictionary.rb
184
- - lib/cequel/model/translation.rb
185
- - lib/cequel/model/subclass_internals.rb
186
- - lib/cequel/model/magic.rb
187
178
  - lib/cequel/model/callbacks.rb
179
+ - lib/cequel/model/naming.rb
180
+ - lib/cequel/model/instance_internals.rb
188
181
  - lib/cequel/model/dynamic.rb
189
- - lib/cequel/model/observer.rb
182
+ - lib/cequel/model/properties.rb
190
183
  - lib/cequel/model/column.rb
191
- - lib/cequel/model/instance_internals.rb
192
- - lib/cequel/model/validations.rb
184
+ - lib/cequel/model/observer.rb
185
+ - lib/cequel/model/mass_assignment_security.rb
186
+ - lib/cequel/model/associations.rb
193
187
  - lib/cequel/model/persistence.rb
194
- - lib/cequel/model/railtie.rb
195
- - lib/cequel/model/properties.rb
196
188
  - lib/cequel/model/scope.rb
189
+ - lib/cequel/model/magic.rb
190
+ - lib/cequel/model/readable_dictionary.rb
191
+ - lib/cequel/model/remote_association.rb
192
+ - lib/cequel/model/class_internals.rb
193
+ - lib/cequel/model/validations.rb
194
+ - lib/cequel/model/railtie.rb
195
+ - lib/cequel/model/translation.rb
197
196
  - lib/cequel/model/scoped.rb
198
- - lib/cequel/model/timestamps.rb
199
- - lib/cequel/model/local_association.rb
200
197
  - lib/cequel/model/dirty.rb
201
198
  - lib/cequel/model/errors.rb
202
- - lib/cequel/model/class_internals.rb
203
- - lib/cequel/keyspace.rb
199
+ - lib/cequel/model/local_association.rb
200
+ - lib/cequel/model/dictionary.rb
201
+ - lib/cequel/model/subclass_internals.rb
202
+ - lib/cequel/model/timestamps.rb
203
+ - lib/cequel/model.rb
204
204
  - lib/cequel/version.rb
205
205
  - lib/cequel/data_set.rb
206
- - lib/cequel/row_specification.rb
207
- - lib/cequel/new_relic_instrumentation.rb
208
- - lib/cequel/model.rb
209
206
  - lib/cequel/batch.rb
207
+ - lib/cequel/new_relic_instrumentation.rb
208
+ - lib/cequel/statement.rb
210
209
  - lib/cequel/errors.rb
211
- - spec/environment.rb
212
- - spec/examples/spec_helper.rb
213
- - spec/examples/data_set_spec.rb
214
- - spec/examples/keyspace_spec.rb
215
- - spec/examples/model/naming_spec.rb
216
- - spec/examples/model/properties_spec.rb
217
- - spec/examples/model/observer_spec.rb
218
- - spec/examples/model/mass_assignment_security_spec.rb
219
- - spec/examples/model/dynamic_spec.rb
220
- - spec/examples/model/dirty_spec.rb
221
- - spec/examples/model/spec_helper.rb
222
- - spec/examples/model/timestamps_spec.rb
223
- - spec/examples/model/persistence_spec.rb
224
- - spec/examples/model/magic_spec.rb
225
- - spec/examples/model/counter_spec.rb
226
- - spec/examples/model/callbacks_spec.rb
227
- - spec/examples/model/inheritable_spec.rb
228
- - spec/examples/model/scope_spec.rb
229
- - spec/examples/model/dictionary_spec.rb
230
- - spec/examples/model/serialization_spec.rb
231
- - spec/examples/model/validations_spec.rb
232
- - spec/examples/model/associations_spec.rb
233
- - spec/examples/model/translation_spec.rb
210
+ - lib/cequel/row_specification.rb
234
211
  - spec/models/post_observer.rb
235
- - spec/models/blog_posts.rb
236
- - spec/models/blog.rb
237
212
  - spec/models/comment_counts.rb
238
- - spec/models/post.rb
213
+ - spec/models/asset_observer.rb
239
214
  - spec/models/photo.rb
240
- - spec/models/asset.rb
241
215
  - spec/models/post_comments.rb
242
216
  - spec/models/comment.rb
243
- - spec/models/asset_observer.rb
217
+ - spec/models/blog_posts.rb
218
+ - spec/models/blog.rb
219
+ - spec/models/asset.rb
220
+ - spec/models/post.rb
244
221
  - spec/models/category.rb
245
222
  - spec/support/helpers.rb
246
223
  - spec/support/result_stub.rb
247
224
  - spec/shared/readable_dictionary.rb
225
+ - spec/environment.rb
226
+ - spec/examples/model/dictionary_spec.rb
227
+ - spec/examples/model/observer_spec.rb
228
+ - spec/examples/model/dirty_spec.rb
229
+ - spec/examples/model/callbacks_spec.rb
230
+ - spec/examples/model/persistence_spec.rb
231
+ - spec/examples/model/serialization_spec.rb
232
+ - spec/examples/model/dynamic_spec.rb
233
+ - spec/examples/model/validations_spec.rb
234
+ - spec/examples/model/scope_spec.rb
235
+ - spec/examples/model/mass_assignment_security_spec.rb
236
+ - spec/examples/model/timestamps_spec.rb
237
+ - spec/examples/model/properties_spec.rb
238
+ - spec/examples/model/counter_spec.rb
239
+ - spec/examples/model/inheritable_spec.rb
240
+ - spec/examples/model/translation_spec.rb
241
+ - spec/examples/model/associations_spec.rb
242
+ - spec/examples/model/naming_spec.rb
243
+ - spec/examples/model/spec_helper.rb
244
+ - spec/examples/model/magic_spec.rb
245
+ - spec/examples/data_set_spec.rb
246
+ - spec/examples/keyspace_spec.rb
247
+ - spec/examples/spec_helper.rb
248
248
  homepage: https://github.com/brewster/cequel
249
249
  licenses:
250
250
  - MIT
@@ -272,26 +272,26 @@ signing_key:
272
272
  specification_version: 3
273
273
  summary: Query abstraction layer and object-row mapper for Cassandra and CQL
274
274
  test_files:
275
- - spec/examples/spec_helper.rb
276
- - spec/examples/data_set_spec.rb
277
- - spec/examples/keyspace_spec.rb
278
- - spec/examples/model/naming_spec.rb
279
- - spec/examples/model/properties_spec.rb
275
+ - spec/examples/model/dictionary_spec.rb
280
276
  - spec/examples/model/observer_spec.rb
281
- - spec/examples/model/mass_assignment_security_spec.rb
282
- - spec/examples/model/dynamic_spec.rb
283
277
  - spec/examples/model/dirty_spec.rb
284
- - spec/examples/model/spec_helper.rb
285
- - spec/examples/model/timestamps_spec.rb
286
- - spec/examples/model/persistence_spec.rb
287
- - spec/examples/model/magic_spec.rb
288
- - spec/examples/model/counter_spec.rb
289
278
  - spec/examples/model/callbacks_spec.rb
290
- - spec/examples/model/inheritable_spec.rb
291
- - spec/examples/model/scope_spec.rb
292
- - spec/examples/model/dictionary_spec.rb
279
+ - spec/examples/model/persistence_spec.rb
293
280
  - spec/examples/model/serialization_spec.rb
281
+ - spec/examples/model/dynamic_spec.rb
294
282
  - spec/examples/model/validations_spec.rb
295
- - spec/examples/model/associations_spec.rb
283
+ - spec/examples/model/scope_spec.rb
284
+ - spec/examples/model/mass_assignment_security_spec.rb
285
+ - spec/examples/model/timestamps_spec.rb
286
+ - spec/examples/model/properties_spec.rb
287
+ - spec/examples/model/counter_spec.rb
288
+ - spec/examples/model/inheritable_spec.rb
296
289
  - spec/examples/model/translation_spec.rb
290
+ - spec/examples/model/associations_spec.rb
291
+ - spec/examples/model/naming_spec.rb
292
+ - spec/examples/model/spec_helper.rb
293
+ - spec/examples/model/magic_spec.rb
294
+ - spec/examples/data_set_spec.rb
295
+ - spec/examples/keyspace_spec.rb
296
+ - spec/examples/spec_helper.rb
297
297
  has_rdoc: false