moneta 1.1.1 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (103) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +176 -0
  3. data/.travis.yml +57 -23
  4. data/CHANGES +12 -0
  5. data/Gemfile +89 -64
  6. data/README.md +40 -14
  7. data/feature_matrix.yaml +1 -0
  8. data/lib/action_dispatch/middleware/session/moneta_store.rb +1 -0
  9. data/lib/active_support/cache/moneta_store.rb +5 -5
  10. data/lib/moneta.rb +9 -1
  11. data/lib/moneta/adapters/activerecord.rb +35 -19
  12. data/lib/moneta/adapters/activesupportcache.rb +3 -7
  13. data/lib/moneta/adapters/cassandra.rb +24 -16
  14. data/lib/moneta/adapters/client.rb +13 -9
  15. data/lib/moneta/adapters/couch.rb +220 -80
  16. data/lib/moneta/adapters/datamapper.rb +1 -0
  17. data/lib/moneta/adapters/file.rb +9 -6
  18. data/lib/moneta/adapters/hbase.rb +1 -1
  19. data/lib/moneta/adapters/kyotocabinet.rb +8 -7
  20. data/lib/moneta/adapters/leveldb.rb +1 -1
  21. data/lib/moneta/adapters/lmdb.rb +3 -4
  22. data/lib/moneta/adapters/lruhash.rb +29 -62
  23. data/lib/moneta/adapters/memcached.rb +1 -0
  24. data/lib/moneta/adapters/memcached/dalli.rb +1 -1
  25. data/lib/moneta/adapters/memcached/native.rb +10 -8
  26. data/lib/moneta/adapters/mongo.rb +1 -0
  27. data/lib/moneta/adapters/mongo/base.rb +3 -3
  28. data/lib/moneta/adapters/mongo/moped.rb +12 -13
  29. data/lib/moneta/adapters/mongo/official.rb +7 -8
  30. data/lib/moneta/adapters/null.rb +1 -2
  31. data/lib/moneta/adapters/pstore.rb +3 -2
  32. data/lib/moneta/adapters/redis.rb +3 -3
  33. data/lib/moneta/adapters/restclient.rb +12 -3
  34. data/lib/moneta/adapters/riak.rb +2 -2
  35. data/lib/moneta/adapters/sequel.rb +112 -119
  36. data/lib/moneta/adapters/sqlite.rb +3 -3
  37. data/lib/moneta/adapters/tokyotyrant.rb +1 -1
  38. data/lib/moneta/builder.rb +0 -1
  39. data/lib/moneta/enumerable.rb +38 -0
  40. data/lib/moneta/expires.rb +12 -12
  41. data/lib/moneta/fallback.rb +84 -0
  42. data/lib/moneta/lock.rb +1 -1
  43. data/lib/moneta/logger.rb +2 -2
  44. data/lib/moneta/mixins.rb +12 -10
  45. data/lib/moneta/optionmerger.rb +0 -1
  46. data/lib/moneta/pool.rb +301 -31
  47. data/lib/moneta/proxy.rb +2 -2
  48. data/lib/moneta/server.rb +9 -12
  49. data/lib/moneta/shared.rb +1 -1
  50. data/lib/moneta/stack.rb +6 -6
  51. data/lib/moneta/synchronize.rb +3 -3
  52. data/lib/moneta/transformer.rb +19 -17
  53. data/lib/moneta/transformer/config.rb +6 -5
  54. data/lib/moneta/transformer/helper.rb +3 -3
  55. data/lib/moneta/transformer/helper/bson.rb +18 -15
  56. data/lib/moneta/utils.rb +3 -9
  57. data/lib/moneta/version.rb +1 -1
  58. data/lib/moneta/weak_each_key.rb +2 -4
  59. data/lib/rack/cache/moneta.rb +16 -13
  60. data/lib/rack/moneta_rest.rb +2 -2
  61. data/lib/rack/session/moneta.rb +3 -4
  62. data/moneta.gemspec +8 -0
  63. data/script/benchmarks +55 -32
  64. data/script/reconfigure-couchdb +13 -0
  65. data/script/start-hbase +1 -0
  66. data/script/start-services +2 -10
  67. data/spec/active_support/cache_moneta_store_spec.rb +3 -1
  68. data/spec/features/concurrent_create.rb +31 -10
  69. data/spec/features/concurrent_increment.rb +27 -19
  70. data/spec/features/increment.rb +41 -41
  71. data/spec/helper.rb +2 -42
  72. data/spec/moneta/adapters/activesupportcache/adapter_activesupportcache_spec.rb +4 -1
  73. data/spec/moneta/adapters/activesupportcache/adapter_activesupportcache_with_default_expires_spec.rb +4 -1
  74. data/spec/moneta/adapters/activesupportcache/standard_activesupportcache_spec.rb +14 -0
  75. data/spec/moneta/adapters/couch/adapter_couch_spec.rb +199 -2
  76. data/spec/moneta/adapters/couch/standard_couch_spec.rb +8 -2
  77. data/spec/moneta/adapters/couch/standard_couch_with_expires_spec.rb +7 -1
  78. data/spec/moneta/adapters/faraday_helper.rb +9 -0
  79. data/spec/moneta/adapters/lruhash/adapter_lruhash_spec.rb +2 -2
  80. data/spec/moneta/adapters/memcached/adapter_memcached_spec.rb +1 -1
  81. data/spec/moneta/adapters/memcached/dalli/adapter_memcached_dalli_spec.rb +1 -1
  82. data/spec/moneta/adapters/memcached/dalli/adapter_memcached_dalli_with_default_expires_spec.rb +1 -1
  83. data/spec/moneta/adapters/memcached/dalli/standard_memcached_dalli_spec.rb +1 -1
  84. data/spec/moneta/adapters/memcached/native/adapter_memcached_native_spec.rb +1 -1
  85. data/spec/moneta/adapters/memcached/native/adapter_memcached_native_with_default_expires_spec.rb +1 -1
  86. data/spec/moneta/adapters/memcached/native/standard_memcached_native_spec.rb +1 -1
  87. data/spec/moneta/adapters/memcached/standard_memcached_spec.rb +1 -1
  88. data/spec/moneta/adapters/{memcached/helper.rb → memcached_helper.rb} +0 -0
  89. data/spec/moneta/adapters/null/null_adapter_spec.rb +1 -1
  90. data/spec/moneta/adapters/restclient/adapter_restclient_spec.rb +7 -5
  91. data/spec/moneta/adapters/restclient/helper.rb +12 -0
  92. data/spec/moneta/adapters/restclient/standard_restclient_spec.rb +9 -6
  93. data/spec/moneta/adapters/riak/standard_riak_with_expires_spec.rb +4 -0
  94. data/spec/moneta/adapters/tokyotyrant/adapter_tokyotyrant_spec.rb +6 -2
  95. data/spec/moneta/adapters/tokyotyrant/helper.rb +12 -0
  96. data/spec/moneta/adapters/tokyotyrant/standard_tokyotyrant_spec.rb +5 -2
  97. data/spec/moneta/adapters/tokyotyrant/standard_tokyotyrant_with_expires_spec.rb +5 -1
  98. data/spec/moneta/proxies/enumerable/enumerable_spec.rb +26 -0
  99. data/spec/moneta/proxies/fallback/fallback_spec.rb +42 -0
  100. data/spec/moneta/proxies/pool/pool_spec.rb +319 -6
  101. data/spec/restserver.rb +40 -0
  102. metadata +122 -7
  103. data/script/install-kyotocabinet +0 -17
@@ -6,8 +6,7 @@ module Moneta
6
6
  include Defaults
7
7
 
8
8
  # @param [Hash] options Options hash
9
- def initialize(options = {})
10
- end
9
+ def initialize(options = {}); end
11
10
 
12
11
  # (see Proxy#key?)
13
12
  def key?(key, options = {})
@@ -48,7 +48,7 @@ module Moneta
48
48
 
49
49
  # (see Proxy#store)
50
50
  def store(key, value, options = {})
51
- transaction {@backend[key] = value }
51
+ transaction { @backend[key] = value }
52
52
  end
53
53
 
54
54
  # (see Proxy#delete)
@@ -59,7 +59,8 @@ module Moneta
59
59
  # (see Proxy#increment)
60
60
  def increment(key, amount = 1, options = {})
61
61
  transaction do
62
- value = Utils.to_int(@backend[key]) + amount
62
+ existing = @backend[key]
63
+ value = (existing == nil ? 0 : Integer(existing)) + amount
63
64
  @backend[key] = value.to_s
64
65
  value
65
66
  end
@@ -100,7 +100,7 @@ module Moneta
100
100
  # (see Defaults#values_at)
101
101
  def values_at(*keys, **options)
102
102
  with_expiry_update(*keys, default: nil, **options) do
103
- @backend.mget *keys
103
+ @backend.mget(*keys)
104
104
  end
105
105
  end
106
106
 
@@ -112,7 +112,7 @@ module Moneta
112
112
  old_values = @backend.mget(*keys)
113
113
  updates = pairs.each_with_index.with_object({}) do |(pair, i), updates|
114
114
  old_value = old_values[i]
115
- if !old_value.nil?
115
+ if old_value != nil
116
116
  key, new_value = pair
117
117
  updates[key] = yield(key, old_value, new_value)
118
118
  end
@@ -146,7 +146,7 @@ module Moneta
146
146
 
147
147
  def with_expiry_update(*keys, default: @default_expires, **options)
148
148
  expires = expires_value(options, default)
149
- if expires.nil?
149
+ if expires == nil
150
150
  yield
151
151
  else
152
152
  future = nil
@@ -11,10 +11,19 @@ module Moneta
11
11
 
12
12
  # @param [Hash] options
13
13
  # @option options [String] :url URL
14
- # @option options [Faraday connection] :backend Use existing backend instance
14
+ # @option options [Symbol] :adapter The adapter to tell Faraday to use
15
+ # @option options [Faraday::Connection] :backend Use existing backend instance
16
+ # @option options Other options passed to {Faraday::new} (unless
17
+ # :backend option is provided).
15
18
  def initialize(options = {})
16
- raise ArgumentError, 'Option :url is required' unless url = options[:url]
17
- @backend = options[:backend] || ::Faraday.new(url: url)
19
+ @backend = options.delete(:backend) ||
20
+ begin
21
+ raise ArgumentError, 'Option :url is required' unless url = options.delete(:url)
22
+ block = if faraday_adapter = options.delete(:adapter)
23
+ proc { |faraday| faraday.adapter faraday_adapter }
24
+ end
25
+ ::Faraday.new(url, options, &block)
26
+ end
18
27
  end
19
28
 
20
29
  # (see Proxy#key?)
@@ -30,7 +30,7 @@ module Moneta
30
30
  # (see Proxy#load)
31
31
  def load(key, options = {})
32
32
  @bucket.get(key, options.dup).raw_data
33
- rescue ::Riak::FailedRequest => ex
33
+ rescue ::Riak::FailedRequest
34
34
  nil
35
35
  end
36
36
 
@@ -53,7 +53,7 @@ module Moneta
53
53
  # (see Proxy#clear)
54
54
  def clear(options = {})
55
55
  @bucket.keys do |keys|
56
- keys.each{ |key| @bucket.delete(key) }
56
+ keys.each { |key| @bucket.delete(key) }
57
57
  end
58
58
  self
59
59
  end
@@ -7,10 +7,6 @@ module Moneta
7
7
  class Sequel
8
8
  include Defaults
9
9
 
10
- # Sequel::UniqueConstraintViolation is defined since sequel 3.44.0
11
- # older versions raise a Sequel::DatabaseError.
12
- UniqueConstraintViolation = defined?(::Sequel::UniqueConstraintViolation) ? ::Sequel::UniqueConstraintViolation : ::Sequel::DatabaseError
13
-
14
10
  supports :create, :increment, :each_key
15
11
  attr_reader :backend, :key_column, :value_column
16
12
 
@@ -43,7 +39,7 @@ module Moneta
43
39
  begin
44
40
  raise ArgumentError, 'Option :db is required' unless db = options.delete(:db)
45
41
  other_cols = [:table, :create_table, :key_column, :value_column, :hstore]
46
- ::Sequel.connect(db, options.reject { |k,_| other_cols.member?(k) }).tap do |backend|
42
+ ::Sequel.connect(db, options.reject { |k,| other_cols.member?(k) }).tap do |backend|
47
43
  if extensions
48
44
  raise ArgumentError, 'Option :extensions must be an Array' unless extensions.is_a?(Array)
49
45
  extensions.map(&:to_sym).each(&backend.method(:extension))
@@ -56,7 +52,7 @@ module Moneta
56
52
  end
57
53
 
58
54
  instance =
59
- if optimize.nil? || optimize
55
+ if optimize == nil || optimize
60
56
  case backend.database_type
61
57
  when :mysql
62
58
  MySQL.allocate
@@ -86,7 +82,7 @@ module Moneta
86
82
  @each_key_server = options.delete(:each_key_server)
87
83
 
88
84
  create_proc = options.delete(:create_table)
89
- if create_proc.nil?
85
+ if create_proc == nil
90
86
  create_table
91
87
  elsif create_proc
92
88
  create_proc.call(@backend)
@@ -124,7 +120,7 @@ module Moneta
124
120
  def create(key, value, options = {})
125
121
  @create.call(key: key, value: blob(value))
126
122
  true
127
- rescue UniqueConstraintViolation
123
+ rescue ::Sequel::ConstraintViolation
128
124
  false
129
125
  end
130
126
 
@@ -231,8 +227,8 @@ module Moneta
231
227
 
232
228
  protected
233
229
 
234
- def blob(s)
235
- ::Sequel.blob(s) unless s == nil
230
+ def blob(str)
231
+ ::Sequel.blob(str) unless str == nil
236
232
  end
237
233
 
238
234
  def blob_pairs(pairs)
@@ -279,41 +275,41 @@ module Moneta
279
275
  end
280
276
 
281
277
  def prepare_key
282
- @key = @table.
283
- where(key_column => :$key).select(1).
284
- prepare(:first, statement_id(:key))
278
+ @key = @table
279
+ .where(key_column => :$key).select(1)
280
+ .prepare(:first, statement_id(:key))
285
281
  end
286
282
 
287
283
  def prepare_load
288
- @load = @table.
289
- where(key_column => :$key).select(value_column).
290
- prepare(:first, statement_id(:load))
284
+ @load = @table
285
+ .where(key_column => :$key).select(value_column)
286
+ .prepare(:first, statement_id(:load))
291
287
  end
292
288
 
293
289
  def prepare_store
294
- @store_update = @table.
295
- where(key_column => :$key).
296
- prepare(:update, statement_id(:store_update), value_column => :$value)
290
+ @store_update = @table
291
+ .where(key_column => :$key)
292
+ .prepare(:update, statement_id(:store_update), value_column => :$value)
297
293
  end
298
294
 
299
295
  def prepare_create
300
- @create = @table.
301
- prepare(:insert, statement_id(:create), key_column => :$key, value_column => :$value)
296
+ @create = @table
297
+ .prepare(:insert, statement_id(:create), key_column => :$key, value_column => :$value)
302
298
  end
303
299
 
304
300
  def prepare_increment
305
- @load_for_update = @table.
306
- where(key_column => :$key).for_update.
307
- select(value_column).
308
- prepare(:first, statement_id(:load_for_update))
309
- @increment_update ||= @table.
310
- where(key_column => :$key, value_column => :$value).
311
- prepare(:update, statement_id(:increment_update), value_column => :$new_value)
301
+ @load_for_update = @table
302
+ .where(key_column => :$key).for_update
303
+ .select(value_column)
304
+ .prepare(:first, statement_id(:load_for_update))
305
+ @increment_update ||= @table
306
+ .where(key_column => :$key, value_column => :$value)
307
+ .prepare(:update, statement_id(:increment_update), value_column => :$new_value)
312
308
  end
313
309
 
314
310
  def prepare_delete
315
- @delete = @table.where(key_column => :$key).
316
- prepare(:delete, statement_id(:delete))
311
+ @delete = @table.where(key_column => :$key)
312
+ .prepare(:delete, statement_id(:delete))
317
313
  end
318
314
 
319
315
  def prepare_slice
@@ -357,9 +353,9 @@ module Moneta
357
353
  def merge!(pairs, options = {}, &block)
358
354
  @backend.transaction do
359
355
  pairs = yield_merge_pairs(pairs, &block) if block_given?
360
- @table.
361
- on_duplicate_key_update.
362
- import([key_column, value_column], blob_pairs(pairs).to_a)
356
+ @table
357
+ .on_duplicate_key_update
358
+ .import([key_column, value_column], blob_pairs(pairs).to_a)
363
359
  end
364
360
 
365
361
  self
@@ -377,15 +373,15 @@ module Moneta
377
373
  protected
378
374
 
379
375
  def prepare_store
380
- @store = @table.
381
- on_duplicate_key_update.
382
- prepare(:insert, statement_id(:store), key_column => :$key, value_column => :$value)
376
+ @store = @table
377
+ .on_duplicate_key_update
378
+ .prepare(:insert, statement_id(:store), key_column => :$key, value_column => :$value)
383
379
  end
384
380
 
385
381
  def prepare_increment
386
- @increment_update = @table.
387
- where(key_column => :$key).
388
- prepare(:update, statement_id(:increment_update), value_column => :$value)
382
+ @increment_update = @table
383
+ .where(key_column => :$key)
384
+ .prepare(:update, statement_id(:increment_update), value_column => :$value)
389
385
  super
390
386
  end
391
387
  end
@@ -414,11 +410,10 @@ module Moneta
414
410
  def merge!(pairs, options = {}, &block)
415
411
  @backend.transaction do
416
412
  pairs = yield_merge_pairs(pairs, &block) if block_given?
417
- @table.
418
- insert_conflict(
419
- target: key_column,
420
- update: {value_column => ::Sequel[:excluded][value_column]}).
421
- import([key_column, value_column], blob_pairs(pairs).to_a)
413
+ @table
414
+ .insert_conflict(target: key_column,
415
+ update: { value_column => ::Sequel[:excluded][value_column] })
416
+ .import([key_column, value_column], blob_pairs(pairs).to_a)
422
417
  end
423
418
 
424
419
  self
@@ -436,31 +431,32 @@ module Moneta
436
431
  protected
437
432
 
438
433
  def prepare_store
439
- @store = @table.
440
- insert_conflict(
441
- target: key_column,
442
- update: {value_column => ::Sequel[:excluded][value_column]}).
443
- prepare(:insert, statement_id(:store), key_column => :$key, value_column => :$value)
434
+ @store = @table
435
+ .insert_conflict(target: key_column,
436
+ update: { value_column => ::Sequel[:excluded][value_column] })
437
+ .prepare(:insert, statement_id(:store), key_column => :$key, value_column => :$value)
444
438
  end
445
439
 
446
440
  def prepare_increment
447
441
  update_expr = ::Sequel[:convert_to].function(
448
442
  (::Sequel[:convert_from].function(
449
443
  ::Sequel[@table_name][value_column],
450
- 'UTF8').cast(Integer) + :$amount).cast(String),
451
- 'UTF8')
444
+ 'UTF8'
445
+ ).cast(Integer) + :$amount).cast(String),
446
+ 'UTF8'
447
+ )
452
448
 
453
- @increment = @table.
454
- returning(value_column).
455
- insert_conflict(target: key_column, update: {value_column => update_expr}).
456
- prepare(:insert, statement_id(:increment), key_column => :$key, value_column => :$value)
449
+ @increment = @table
450
+ .returning(value_column)
451
+ .insert_conflict(target: key_column, update: { value_column => update_expr })
452
+ .prepare(:insert, statement_id(:increment), key_column => :$key, value_column => :$value)
457
453
  end
458
454
 
459
455
  def prepare_delete
460
- @delete = @table.
461
- returning(value_column).
462
- where(key_column => :$key).
463
- prepare(:delete, statement_id(:delete))
456
+ @delete = @table
457
+ .returning(value_column)
458
+ .where(key_column => :$key)
459
+ .prepare(:delete, statement_id(:delete))
464
460
  end
465
461
  end
466
462
 
@@ -521,10 +517,10 @@ module Moneta
521
517
  if @create
522
518
  @create.call(row: @row, key: key, pair: ::Sequel.hstore(key => value))
523
519
  else
524
- @table.
525
- where(key_column => @row).
526
- exclude(::Sequel[value_column].hstore.key?(key)).
527
- update(value_column => ::Sequel[value_column].hstore.merge(key => value))
520
+ @table
521
+ .where(key_column => @row)
522
+ .exclude(::Sequel[value_column].hstore.key?(key))
523
+ .update(value_column => ::Sequel[value_column].hstore.merge(key => value))
528
524
  end
529
525
  end
530
526
  end
@@ -571,9 +567,9 @@ module Moneta
571
567
  @table
572
568
  end
573
569
  ds = ds.order(:skeys) unless @table.respond_to?(:use_cursor)
574
- ds.where(key_column => @row).
575
- select(::Sequel[value_column].hstore.skeys).
576
- paged_each do |row|
570
+ ds.where(key_column => @row)
571
+ .select(::Sequel[value_column].hstore.skeys)
572
+ .paged_each do |row|
577
573
  yield row[:skeys]
578
574
  end
579
575
  self
@@ -614,9 +610,9 @@ module Moneta
614
610
  end
615
611
 
616
612
  def prepare_create_row
617
- @create_row = @table.
618
- insert_ignore.
619
- prepare(:insert, statement_id(:hstore_create_row), key_column => :$row, value_column => '')
613
+ @create_row = @table
614
+ .insert_ignore
615
+ .prepare(:insert, statement_id(:hstore_create_row), key_column => :$row, value_column => '')
620
616
  end
621
617
 
622
618
  def prepare_clear
@@ -629,40 +625,40 @@ module Moneta
629
625
  ds.where(key_column => @row).select(::Sequel[value_column].hstore.key?(pl.arg))
630
626
  end
631
627
  else
632
- @key = @table.where(key_column => :$row).
633
- select(::Sequel[value_column].hstore.key?(:$key).as(:present)).
634
- prepare(:first, statement_id(:hstore_key))
628
+ @key = @table.where(key_column => :$row)
629
+ .select(::Sequel[value_column].hstore.key?(:$key).as(:present))
630
+ .prepare(:first, statement_id(:hstore_key))
635
631
  end
636
632
  end
637
633
 
638
634
  def prepare_store
639
- @store = @table.
640
- where(key_column => :$row).
641
- prepare(:update, statement_id(:hstore_store), value_column => ::Sequel[value_column].hstore.merge(:$pair))
635
+ @store = @table
636
+ .where(key_column => :$row)
637
+ .prepare(:update, statement_id(:hstore_store), value_column => ::Sequel[value_column].hstore.merge(:$pair))
642
638
  end
643
639
 
644
640
  def prepare_increment
645
- pair = ::Sequel[:hstore].function(
646
- :$key,
647
- (::Sequel[:coalesce].function(
648
- ::Sequel[value_column].hstore[:$key].cast(Integer),
649
- 0) + :$amount).cast(String))
641
+ pair = ::Sequel[:hstore]
642
+ .function(:$key, (
643
+ ::Sequel[:coalesce].function(::Sequel[value_column].hstore[:$key].cast(Integer), 0) +
644
+ :$amount
645
+ ).cast(String))
650
646
 
651
- @increment = @table.
652
- returning(::Sequel[value_column].hstore[:$key].as(:value)).
653
- where(key_column => :$row).
654
- prepare(:update, statement_id(:hstore_increment), value_column => ::Sequel.join([value_column, pair]))
647
+ @increment = @table
648
+ .returning(::Sequel[value_column].hstore[:$key].as(:value))
649
+ .where(key_column => :$row)
650
+ .prepare(:update, statement_id(:hstore_increment), value_column => ::Sequel.join([value_column, pair]))
655
651
  end
656
652
 
657
653
  def prepare_load
658
- @load = @table.where(key_column => :$row).
659
- select(::Sequel[value_column].hstore[:$key].as(:value)).
660
- prepare(:first, statement_id(:hstore_load))
654
+ @load = @table.where(key_column => :$row)
655
+ .select(::Sequel[value_column].hstore[:$key].as(:value))
656
+ .prepare(:first, statement_id(:hstore_load))
661
657
  end
662
658
 
663
659
  def prepare_delete
664
- @delete = @table.where(key_column => :$row).
665
- prepare(:update, statement_id(:hstore_delete), value_column => ::Sequel[value_column].hstore.delete(:$key))
660
+ @delete = @table.where(key_column => :$row)
661
+ .prepare(:update, statement_id(:hstore_delete), value_column => ::Sequel[value_column].hstore.delete(:$key))
666
662
  end
667
663
 
668
664
  def prepare_create
@@ -670,35 +666,33 @@ module Moneta
670
666
  # the hstore `?` (key?) operator. See
671
667
  # https://stackoverflow.com/questions/11940401/escaping-hstore-contains-operators-in-a-jdbc-prepared-statement
672
668
  return if defined?(JRUBY_VERSION)
673
- @create = @table.
674
- where(key_column => :$row).
675
- exclude(::Sequel[value_column].hstore.key?(:$key)).
676
- prepare(:update, statement_id(:hstore_create), value_column => ::Sequel[value_column].hstore.merge(:$pair))
669
+ @create = @table
670
+ .where(key_column => :$row)
671
+ .exclude(::Sequel[value_column].hstore.key?(:$key))
672
+ .prepare(:update, statement_id(:hstore_create), value_column => ::Sequel[value_column].hstore.merge(:$pair))
677
673
  end
678
674
 
679
675
  def prepare_values_at
680
- @values_at = @table.
681
- where(key_column => :$row).
682
- select(::Sequel[value_column].hstore[::Sequel.cast(:$keys, :"text[]")].as(:values)).
683
- prepare(:first, statement_id(:hstore_values_at))
676
+ @values_at = @table
677
+ .where(key_column => :$row)
678
+ .select(::Sequel[value_column].hstore[::Sequel.cast(:$keys, :"text[]")].as(:values))
679
+ .prepare(:first, statement_id(:hstore_values_at))
684
680
  end
685
681
 
686
682
  def prepare_slice
687
- slice = @table.
688
- where(key_column => :$row).
689
- select(::Sequel[value_column].hstore.slice(:$keys).as(:pairs))
683
+ slice = @table
684
+ .where(key_column => :$row)
685
+ .select(::Sequel[value_column].hstore.slice(:$keys).as(:pairs))
690
686
  @slice = slice.prepare(:first, statement_id(:hstore_slice))
691
687
  @slice_for_update = slice.for_update.prepare(:first, statement_id(:hstore_slice_for_update))
692
688
  end
693
689
 
694
690
  def prepare_size
695
- @size =
696
- @backend.from(
697
- @table.
698
- where(key_column => :$row).
699
- select(::Sequel[value_column].hstore.each)).
700
- select { count.function.*.as(:size) }.
701
- prepare(:first, statement_id(:hstore_size))
691
+ @size = @backend
692
+ .from(@table.where(key_column => :$row)
693
+ .select(::Sequel[value_column].hstore.each))
694
+ .select { count.function.*.as(:size) }
695
+ .prepare(:first, statement_id(:hstore_size))
702
696
  end
703
697
  end
704
698
 
@@ -719,7 +713,7 @@ module Moneta
719
713
  def increment(key, amount = 1, options = {})
720
714
  return super unless @can_upsert
721
715
  @backend.transaction do
722
- @increment.call(key: key, value: amount.to_s, amount: amount)
716
+ @increment.call(key: key, value: blob(amount.to_s), amount: amount)
723
717
  Integer(load(key))
724
718
  end
725
719
  end
@@ -736,23 +730,22 @@ module Moneta
736
730
  protected
737
731
 
738
732
  def prepare_store
739
- @store = @table.
740
- insert_conflict(:replace).
741
- prepare(:insert, statement_id(:store), key_column => :$key, value_column => :$value)
733
+ @store = @table
734
+ .insert_conflict(:replace)
735
+ .prepare(:insert, statement_id(:store), key_column => :$key, value_column => :$value)
742
736
  end
743
737
 
744
738
  def prepare_increment
745
739
  return super unless @can_upsert
746
740
  update_expr = (::Sequel[value_column].cast(Integer) + :$amount).cast(:blob)
747
- @increment = @table.
748
- insert_conflict(
741
+ @increment = @table
742
+ .insert_conflict(
749
743
  target: key_column,
750
- update: {value_column => update_expr},
751
- update_where:
752
- ::Sequel.|(
753
- {value_column => blob("0")},
754
- ::Sequel.~(::Sequel[value_column].cast(Integer)) => 0)).
755
- prepare(:insert, statement_id(:increment), key_column => :$key, value_column => :$value)
744
+ update: { value_column => update_expr },
745
+ update_where: ::Sequel.|({ value_column => blob("0") },
746
+ { ::Sequel.~(::Sequel[value_column].cast(Integer)) => 0 })
747
+ )
748
+ .prepare(:insert, statement_id(:increment), key_column => :$key, value_column => :$value)
756
749
  end
757
750
  end
758
751
  end