moneta 1.4.2 → 1.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +35 -38
- data/CHANGES +9 -0
- data/CONTRIBUTORS +2 -0
- data/Gemfile +143 -55
- data/README.md +5 -4
- data/lib/moneta/adapter.rb +52 -0
- data/lib/moneta/adapters/activerecord.rb +77 -68
- data/lib/moneta/adapters/activesupportcache.rb +22 -31
- data/lib/moneta/adapters/cassandra.rb +114 -116
- data/lib/moneta/adapters/client.rb +17 -18
- data/lib/moneta/adapters/couch.rb +31 -26
- data/lib/moneta/adapters/datamapper.rb +9 -5
- data/lib/moneta/adapters/daybreak.rb +15 -21
- data/lib/moneta/adapters/dbm.rb +6 -12
- data/lib/moneta/adapters/file.rb +21 -13
- data/lib/moneta/adapters/fog.rb +5 -6
- data/lib/moneta/adapters/gdbm.rb +6 -12
- data/lib/moneta/adapters/hbase.rb +10 -12
- data/lib/moneta/adapters/kyotocabinet.rb +22 -27
- data/lib/moneta/adapters/leveldb.rb +14 -20
- data/lib/moneta/adapters/lmdb.rb +19 -22
- data/lib/moneta/adapters/localmemcache.rb +7 -13
- data/lib/moneta/adapters/lruhash.rb +20 -20
- data/lib/moneta/adapters/memcached/dalli.rb +25 -33
- data/lib/moneta/adapters/memcached/native.rb +14 -20
- data/lib/moneta/adapters/memory.rb +5 -7
- data/lib/moneta/adapters/mongo.rb +53 -52
- data/lib/moneta/adapters/pstore.rb +21 -27
- data/lib/moneta/adapters/redis.rb +42 -37
- data/lib/moneta/adapters/restclient.rb +17 -25
- data/lib/moneta/adapters/riak.rb +8 -9
- data/lib/moneta/adapters/sdbm.rb +6 -12
- data/lib/moneta/adapters/sequel/mysql.rb +8 -8
- data/lib/moneta/adapters/sequel/postgres.rb +17 -17
- data/lib/moneta/adapters/sequel/postgres_hstore.rb +47 -47
- data/lib/moneta/adapters/sequel/sqlite.rb +9 -9
- data/lib/moneta/adapters/sequel.rb +56 -65
- data/lib/moneta/adapters/sqlite.rb +37 -35
- data/lib/moneta/adapters/tdb.rb +8 -14
- data/lib/moneta/adapters/tokyocabinet.rb +19 -17
- data/lib/moneta/adapters/tokyotyrant.rb +29 -30
- data/lib/moneta/adapters/yaml.rb +1 -5
- data/lib/moneta/config.rb +101 -0
- data/lib/moneta/expires.rb +0 -1
- data/lib/moneta/expires_support.rb +3 -4
- data/lib/moneta/pool.rb +1 -1
- data/lib/moneta/proxy.rb +29 -0
- data/lib/moneta/server.rb +21 -14
- data/lib/moneta/version.rb +1 -1
- data/lib/moneta/wrapper.rb +5 -0
- data/lib/moneta.rb +2 -0
- data/moneta.gemspec +1 -0
- data/spec/moneta/adapters/client/client_helper.rb +4 -3
- data/spec/moneta/adapters/faraday_helper.rb +3 -2
- data/spec/moneta/adapters/lruhash/adapter_lruhash_spec.rb +10 -6
- data/spec/moneta/adapters/mongo/adapter_mongo_spec.rb +2 -2
- data/spec/moneta/config_spec.rb +219 -0
- data/spec/moneta/proxies/transformer/transformer_bson_spec.rb +3 -1
- data/spec/moneta/proxies/transformer/transformer_marshal_escape_spec.rb +2 -0
- data/spec/rack/session_moneta_spec.rb +44 -25
- data/spec/restserver.rb +3 -14
- metadata +24 -6
@@ -4,55 +4,47 @@ module Moneta
|
|
4
4
|
module Adapters
|
5
5
|
# Moneta rest client backend which works together with {Rack::MonetaRest}
|
6
6
|
# @api public
|
7
|
-
class RestClient
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
#
|
13
|
-
#
|
14
|
-
#
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
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
|
7
|
+
class RestClient < Adapter
|
8
|
+
# @!method initialize(options = {})
|
9
|
+
# @param [Hash] options
|
10
|
+
# @option options [String] :url URL
|
11
|
+
# @option options [Symbol] :adapter The adapter to tell Faraday to use
|
12
|
+
# @option options [Faraday::Connection] :backend Use existing backend instance
|
13
|
+
# @option options Other options passed to {Faraday::new} (unless
|
14
|
+
# :backend option is provided).
|
15
|
+
backend do |url:, adapter: nil, **options|
|
16
|
+
::Faraday.new(url, options) do |faraday|
|
17
|
+
faraday.adapter adapter if adapter
|
18
|
+
end
|
27
19
|
end
|
28
20
|
|
29
21
|
# (see Proxy#key?)
|
30
22
|
def key?(key, options = {})
|
31
|
-
|
23
|
+
backend.head(key).status == 200
|
32
24
|
end
|
33
25
|
|
34
26
|
# (see Proxy#load)
|
35
27
|
def load(key, options = {})
|
36
|
-
response =
|
28
|
+
response = backend.get(key)
|
37
29
|
response.status == 200 ? response.body : nil
|
38
30
|
end
|
39
31
|
|
40
32
|
# (see Proxy#store)
|
41
33
|
def store(key, value, options = {})
|
42
|
-
response =
|
34
|
+
response = backend.post(key, value)
|
43
35
|
raise "HTTP error #{response.status}" unless response.status == 200
|
44
36
|
value
|
45
37
|
end
|
46
38
|
|
47
39
|
# (see Proxy#delete)
|
48
40
|
def delete(key, options = {})
|
49
|
-
response =
|
41
|
+
response = backend.delete(key)
|
50
42
|
response.status == 200 ? response.body : nil
|
51
43
|
end
|
52
44
|
|
53
45
|
# (see Proxy#clear)
|
54
46
|
def clear(options = {})
|
55
|
-
|
47
|
+
backend.delete ''
|
56
48
|
self
|
57
49
|
end
|
58
50
|
end
|
data/lib/moneta/adapters/riak.rb
CHANGED
@@ -5,21 +5,20 @@ module Moneta
|
|
5
5
|
# Riak backend
|
6
6
|
# @api public
|
7
7
|
# @author Potapov Sergey (aka Blake)
|
8
|
-
class Riak
|
9
|
-
|
8
|
+
class Riak < Adapter
|
9
|
+
config :bucket, default: 'moneta'
|
10
|
+
config :content_type, default: 'application/octet-stream'
|
10
11
|
|
11
|
-
|
12
|
+
backend { |**options| ::Riak::Client.new(options) }
|
12
13
|
|
13
14
|
# @param [Hash] options
|
14
15
|
# @option options [String] :bucket ('moneta') Bucket name
|
15
16
|
# @option options [String] :content_type ('application/octet-stream') Default content type
|
16
|
-
# @option options All other options passed to `Riak::Client#new`
|
17
17
|
# @option options [::Riak::Client] :backend Use existing backend instance
|
18
|
+
# @option options All other options passed to `Riak::Client#new`
|
18
19
|
def initialize(options = {})
|
19
|
-
|
20
|
-
@
|
21
|
-
@backend = options[:backend] || ::Riak::Client.new(options)
|
22
|
-
@bucket = @backend.bucket(bucket)
|
20
|
+
super
|
21
|
+
@bucket = backend.bucket(config.bucket)
|
23
22
|
end
|
24
23
|
|
25
24
|
# (see Proxy#key?)
|
@@ -44,7 +43,7 @@ module Moneta
|
|
44
43
|
# (see Proxy#store)
|
45
44
|
def store(key, value, options = {})
|
46
45
|
obj = ::Riak::RObject.new(@bucket, key)
|
47
|
-
obj.content_type = options[:content_type] ||
|
46
|
+
obj.content_type = options[:content_type] || config.content_type
|
48
47
|
obj.raw_data = value
|
49
48
|
obj.store(options.dup)
|
50
49
|
value
|
data/lib/moneta/adapters/sdbm.rb
CHANGED
@@ -4,23 +4,17 @@ module Moneta
|
|
4
4
|
module Adapters
|
5
5
|
# SDBM backend
|
6
6
|
# @api public
|
7
|
-
class SDBM
|
8
|
-
include Defaults
|
7
|
+
class SDBM < Adapter
|
9
8
|
include DBMAdapter
|
10
9
|
include IncrementSupport
|
11
10
|
include CreateSupport
|
12
11
|
include EachKeySupport
|
13
12
|
|
14
|
-
#
|
15
|
-
#
|
16
|
-
#
|
17
|
-
|
18
|
-
|
19
|
-
begin
|
20
|
-
raise ArgumentError, 'Option :file is required' unless options[:file]
|
21
|
-
::SDBM.new(options[:file])
|
22
|
-
end
|
23
|
-
end
|
13
|
+
# @!method initialize(options = {})
|
14
|
+
# @param [Hash] options
|
15
|
+
# @option options [String] :file Database file
|
16
|
+
# @option options [::SDBM] :backend Use existing backend instance
|
17
|
+
backend { |file:| ::SDBM.new(file) }
|
24
18
|
end
|
25
19
|
end
|
26
20
|
end
|
@@ -14,7 +14,7 @@ module Moneta
|
|
14
14
|
# "gap lock").
|
15
15
|
if row = @load_for_update.call(key: key)
|
16
16
|
# Integer() will raise an exception if the existing value cannot be parsed
|
17
|
-
amount += Integer(row[value_column])
|
17
|
+
amount += Integer(row[config.value_column])
|
18
18
|
@increment_update.call(key: key, value: amount)
|
19
19
|
else
|
20
20
|
@create.call(key: key, value: amount)
|
@@ -31,17 +31,17 @@ module Moneta
|
|
31
31
|
pairs = yield_merge_pairs(pairs, &block) if block_given?
|
32
32
|
@table
|
33
33
|
.on_duplicate_key_update
|
34
|
-
.import([key_column, value_column], blob_pairs(pairs).to_a)
|
34
|
+
.import([config.key_column, config.value_column], blob_pairs(pairs).to_a)
|
35
35
|
end
|
36
36
|
|
37
37
|
self
|
38
38
|
end
|
39
39
|
|
40
40
|
def each_key
|
41
|
-
return super unless block_given? &&
|
41
|
+
return super unless block_given? && config.each_key_server && @table.respond_to?(:stream)
|
42
42
|
# Order is not required when streaming
|
43
|
-
@table.server(
|
44
|
-
yield row[key_column]
|
43
|
+
@table.server(config.each_key_server).select(config.key_column).paged_each do |row|
|
44
|
+
yield row[config.key_column]
|
45
45
|
end
|
46
46
|
self
|
47
47
|
end
|
@@ -51,13 +51,13 @@ module Moneta
|
|
51
51
|
def prepare_store
|
52
52
|
@store = @table
|
53
53
|
.on_duplicate_key_update
|
54
|
-
.prepare(:insert, statement_id(:store), key_column => :$key, value_column => :$value)
|
54
|
+
.prepare(:insert, statement_id(:store), config.key_column => :$key, config.value_column => :$value)
|
55
55
|
end
|
56
56
|
|
57
57
|
def prepare_increment
|
58
58
|
@increment_update = @table
|
59
|
-
.where(key_column => :$key)
|
60
|
-
.prepare(:update, statement_id(:increment_update), value_column => :$value)
|
59
|
+
.where(config.key_column => :$key)
|
60
|
+
.prepare(:update, statement_id(:increment_update), config.value_column => :$value)
|
61
61
|
super
|
62
62
|
end
|
63
63
|
end
|
@@ -12,14 +12,14 @@ module Moneta
|
|
12
12
|
def increment(key, amount = 1, options = {})
|
13
13
|
result = @increment.call(key: key, value: blob(amount.to_s), amount: amount)
|
14
14
|
if row = result.first
|
15
|
-
row[value_column].to_i
|
15
|
+
row[config.value_column].to_i
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
19
|
def delete(key, options = {})
|
20
20
|
result = @delete.call(key: key)
|
21
21
|
if row = result.first
|
22
|
-
row[value_column]
|
22
|
+
row[config.value_column]
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
@@ -27,19 +27,19 @@ module Moneta
|
|
27
27
|
@backend.transaction do
|
28
28
|
pairs = yield_merge_pairs(pairs, &block) if block_given?
|
29
29
|
@table
|
30
|
-
.insert_conflict(target: key_column,
|
31
|
-
update: { value_column => ::Sequel[:excluded][value_column] })
|
32
|
-
.import([key_column, value_column], blob_pairs(pairs).to_a)
|
30
|
+
.insert_conflict(target: config.key_column,
|
31
|
+
update: { config.value_column => ::Sequel[:excluded][config.value_column] })
|
32
|
+
.import([config.key_column, config.value_column], blob_pairs(pairs).to_a)
|
33
33
|
end
|
34
34
|
|
35
35
|
self
|
36
36
|
end
|
37
37
|
|
38
38
|
def each_key
|
39
|
-
return super unless block_given? &&
|
39
|
+
return super unless block_given? && !config.each_key_server && @table.respond_to?(:use_cursor)
|
40
40
|
# With a cursor, this will Just Work.
|
41
|
-
@table.select(key_column).paged_each do |row|
|
42
|
-
yield row[key_column]
|
41
|
+
@table.select(config.key_column).paged_each do |row|
|
42
|
+
yield row[config.key_column]
|
43
43
|
end
|
44
44
|
self
|
45
45
|
end
|
@@ -48,30 +48,30 @@ module Moneta
|
|
48
48
|
|
49
49
|
def prepare_store
|
50
50
|
@store = @table
|
51
|
-
.insert_conflict(target: key_column,
|
52
|
-
update: { value_column => ::Sequel[:excluded][value_column] })
|
53
|
-
.prepare(:insert, statement_id(:store), key_column => :$key, value_column => :$value)
|
51
|
+
.insert_conflict(target: config.key_column,
|
52
|
+
update: { config.value_column => ::Sequel[:excluded][config.value_column] })
|
53
|
+
.prepare(:insert, statement_id(:store), config.key_column => :$key, config.value_column => :$value)
|
54
54
|
end
|
55
55
|
|
56
56
|
def prepare_increment
|
57
57
|
update_expr = ::Sequel[:convert_to].function(
|
58
58
|
(::Sequel[:convert_from].function(
|
59
|
-
::Sequel[
|
59
|
+
::Sequel[config.table][config.value_column],
|
60
60
|
'UTF8'
|
61
61
|
).cast(Integer) + :$amount).cast(String),
|
62
62
|
'UTF8'
|
63
63
|
)
|
64
64
|
|
65
65
|
@increment = @table
|
66
|
-
.returning(value_column)
|
67
|
-
.insert_conflict(target: key_column, update: { value_column => update_expr })
|
68
|
-
.prepare(:insert, statement_id(:increment), key_column => :$key, value_column => :$value)
|
66
|
+
.returning(config.value_column)
|
67
|
+
.insert_conflict(target: config.key_column, update: { config.value_column => update_expr })
|
68
|
+
.prepare(:insert, statement_id(:increment), config.key_column => :$key, config.value_column => :$value)
|
69
69
|
end
|
70
70
|
|
71
71
|
def prepare_delete
|
72
72
|
@delete = @table
|
73
|
-
.returning(value_column)
|
74
|
-
.where(key_column => :$key)
|
73
|
+
.returning(config.value_column)
|
74
|
+
.where(config.key_column => :$key)
|
75
75
|
.prepare(:delete, statement_id(:delete))
|
76
76
|
end
|
77
77
|
end
|
@@ -12,7 +12,7 @@ module Moneta
|
|
12
12
|
|
13
13
|
def key?(key, options = {})
|
14
14
|
if @key
|
15
|
-
row = @key.call(row:
|
15
|
+
row = @key.call(row: config.hstore, key: key) || false
|
16
16
|
row && row[:present]
|
17
17
|
else
|
18
18
|
@key_pl.get(key)
|
@@ -22,13 +22,13 @@ module Moneta
|
|
22
22
|
def store(key, value, options = {})
|
23
23
|
@backend.transaction do
|
24
24
|
create_row
|
25
|
-
@store.call(row:
|
25
|
+
@store.call(row: config.hstore, pair: ::Sequel.hstore(key => value))
|
26
26
|
end
|
27
27
|
value
|
28
28
|
end
|
29
29
|
|
30
30
|
def load(key, options = {})
|
31
|
-
if row = @load.call(row:
|
31
|
+
if row = @load.call(row: config.hstore, key: key)
|
32
32
|
row[:value]
|
33
33
|
end
|
34
34
|
end
|
@@ -36,7 +36,7 @@ module Moneta
|
|
36
36
|
def delete(key, options = {})
|
37
37
|
@backend.transaction do
|
38
38
|
value = load(key, options)
|
39
|
-
@delete.call(row:
|
39
|
+
@delete.call(row: config.hstore, key: key)
|
40
40
|
value
|
41
41
|
end
|
42
42
|
end
|
@@ -44,7 +44,7 @@ module Moneta
|
|
44
44
|
def increment(key, amount = 1, options = {})
|
45
45
|
@backend.transaction do
|
46
46
|
create_row
|
47
|
-
if row = @increment.call(row:
|
47
|
+
if row = @increment.call(row: config.hstore, key: key, amount: amount).first
|
48
48
|
row[:value].to_i
|
49
49
|
end
|
50
50
|
end
|
@@ -55,23 +55,23 @@ module Moneta
|
|
55
55
|
create_row
|
56
56
|
1 ==
|
57
57
|
if @create
|
58
|
-
@create.call(row:
|
58
|
+
@create.call(row: config.hstore, key: key, pair: ::Sequel.hstore(key => value))
|
59
59
|
else
|
60
60
|
@table
|
61
|
-
.where(key_column =>
|
62
|
-
.exclude(::Sequel[value_column].hstore.key?(key))
|
63
|
-
.update(value_column => ::Sequel[value_column].hstore.merge(key => value))
|
61
|
+
.where(config.key_column => config.hstore)
|
62
|
+
.exclude(::Sequel[config.value_column].hstore.key?(key))
|
63
|
+
.update(config.value_column => ::Sequel[config.value_column].hstore.merge(key => value))
|
64
64
|
end
|
65
65
|
end
|
66
66
|
end
|
67
67
|
|
68
68
|
def clear(options = {})
|
69
|
-
@clear.call(row:
|
69
|
+
@clear.call(row: config.hstore)
|
70
70
|
self
|
71
71
|
end
|
72
72
|
|
73
73
|
def values_at(*keys, **options)
|
74
|
-
if row = @values_at.call(row:
|
74
|
+
if row = @values_at.call(row: config.hstore, keys: ::Sequel.pg_array(keys))
|
75
75
|
row[:values].to_a
|
76
76
|
else
|
77
77
|
[]
|
@@ -79,7 +79,7 @@ module Moneta
|
|
79
79
|
end
|
80
80
|
|
81
81
|
def slice(*keys, **options)
|
82
|
-
if row = @slice.call(row:
|
82
|
+
if row = @slice.call(row: config.hstore, keys: ::Sequel.pg_array(keys))
|
83
83
|
row[:pairs].to_h
|
84
84
|
else
|
85
85
|
[]
|
@@ -91,24 +91,24 @@ module Moneta
|
|
91
91
|
create_row
|
92
92
|
pairs = yield_merge_pairs(pairs, &block) if block_given?
|
93
93
|
hash = Hash === pairs ? pairs : Hash[pairs.to_a]
|
94
|
-
@store.call(row:
|
94
|
+
@store.call(row: config.hstore, pair: ::Sequel.hstore(hash))
|
95
95
|
end
|
96
96
|
|
97
97
|
self
|
98
98
|
end
|
99
99
|
|
100
100
|
def each_key
|
101
|
-
return enum_for(:each_key) { @size.call(row:
|
101
|
+
return enum_for(:each_key) { @size.call(row: config.hstore)[:size] } unless block_given?
|
102
102
|
|
103
103
|
ds =
|
104
|
-
if
|
105
|
-
@table.server(
|
104
|
+
if config.each_key_server
|
105
|
+
@table.server(config.each_key_server)
|
106
106
|
else
|
107
107
|
@table
|
108
108
|
end
|
109
109
|
ds = ds.order(:skeys) unless @table.respond_to?(:use_cursor)
|
110
|
-
ds.where(key_column =>
|
111
|
-
.select(::Sequel[value_column].hstore.skeys)
|
110
|
+
ds.where(config.key_column => config.hstore)
|
111
|
+
.select(::Sequel[config.value_column].hstore.skeys)
|
112
112
|
.paged_each do |row|
|
113
113
|
yield row[:skeys]
|
114
114
|
end
|
@@ -118,14 +118,14 @@ module Moneta
|
|
118
118
|
protected
|
119
119
|
|
120
120
|
def create_row
|
121
|
-
@create_row.call(row:
|
121
|
+
@create_row.call(row: config.hstore)
|
122
122
|
end
|
123
123
|
|
124
124
|
def create_table
|
125
|
-
key_column =
|
126
|
-
value_column =
|
125
|
+
key_column = config.key_column
|
126
|
+
value_column = config.value_column
|
127
127
|
|
128
|
-
@backend.create_table?(
|
128
|
+
@backend.create_table?(config.table) do
|
129
129
|
column key_column, String, null: false, primary_key: true
|
130
130
|
column value_column, :hstore
|
131
131
|
index value_column, type: :gin
|
@@ -134,7 +134,7 @@ module Moneta
|
|
134
134
|
|
135
135
|
def slice_for_update(pairs)
|
136
136
|
keys = pairs.map { |k, _| k }.to_a
|
137
|
-
if row = @slice_for_update.call(row:
|
137
|
+
if row = @slice_for_update.call(row: config.hstore, keys: ::Sequel.pg_array(keys))
|
138
138
|
row[:pairs].to_h
|
139
139
|
else
|
140
140
|
{}
|
@@ -152,53 +152,53 @@ module Moneta
|
|
152
152
|
def prepare_create_row
|
153
153
|
@create_row = @table
|
154
154
|
.insert_ignore
|
155
|
-
.prepare(:insert, statement_id(:hstore_create_row), key_column => :$row, value_column => '')
|
155
|
+
.prepare(:insert, statement_id(:hstore_create_row), config.key_column => :$row, config.value_column => '')
|
156
156
|
end
|
157
157
|
|
158
158
|
def prepare_clear
|
159
|
-
@clear = @table.where(key_column => :$row).prepare(:update, statement_id(:hstore_clear), value_column => '')
|
159
|
+
@clear = @table.where(config.key_column => :$row).prepare(:update, statement_id(:hstore_clear), config.value_column => '')
|
160
160
|
end
|
161
161
|
|
162
162
|
def prepare_key
|
163
163
|
if defined?(JRUBY_VERSION)
|
164
164
|
@key_pl = ::Sequel::Dataset::PlaceholderLiteralizer.loader(@table) do |pl, ds|
|
165
|
-
ds.where(key_column =>
|
165
|
+
ds.where(config.key_column => config.hstore).select(::Sequel[config.value_column].hstore.key?(pl.arg))
|
166
166
|
end
|
167
167
|
else
|
168
|
-
@key = @table.where(key_column => :$row)
|
169
|
-
.select(::Sequel[value_column].hstore.key?(:$key).as(:present))
|
168
|
+
@key = @table.where(config.key_column => :$row)
|
169
|
+
.select(::Sequel[config.value_column].hstore.key?(:$key).as(:present))
|
170
170
|
.prepare(:first, statement_id(:hstore_key))
|
171
171
|
end
|
172
172
|
end
|
173
173
|
|
174
174
|
def prepare_store
|
175
175
|
@store = @table
|
176
|
-
.where(key_column => :$row)
|
177
|
-
.prepare(:update, statement_id(:hstore_store), value_column => ::Sequel[value_column].hstore.merge(:$pair))
|
176
|
+
.where(config.key_column => :$row)
|
177
|
+
.prepare(:update, statement_id(:hstore_store), config.value_column => ::Sequel[config.value_column].hstore.merge(:$pair))
|
178
178
|
end
|
179
179
|
|
180
180
|
def prepare_increment
|
181
181
|
pair = ::Sequel[:hstore]
|
182
182
|
.function(:$key, (
|
183
|
-
::Sequel[:coalesce].function(::Sequel[value_column].hstore[:$key].cast(Integer), 0) +
|
183
|
+
::Sequel[:coalesce].function(::Sequel[config.value_column].hstore[:$key].cast(Integer), 0) +
|
184
184
|
:$amount
|
185
185
|
).cast(String))
|
186
186
|
|
187
187
|
@increment = @table
|
188
|
-
.returning(::Sequel[value_column].hstore[:$key].as(:value))
|
189
|
-
.where(key_column => :$row)
|
190
|
-
.prepare(:update, statement_id(:hstore_increment), value_column => ::Sequel.join([value_column, pair]))
|
188
|
+
.returning(::Sequel[config.value_column].hstore[:$key].as(:value))
|
189
|
+
.where(config.key_column => :$row)
|
190
|
+
.prepare(:update, statement_id(:hstore_increment), config.value_column => ::Sequel.join([config.value_column, pair]))
|
191
191
|
end
|
192
192
|
|
193
193
|
def prepare_load
|
194
|
-
@load = @table.where(key_column => :$row)
|
195
|
-
.select(::Sequel[value_column].hstore[:$key].as(:value))
|
194
|
+
@load = @table.where(config.key_column => :$row)
|
195
|
+
.select(::Sequel[config.value_column].hstore[:$key].as(:value))
|
196
196
|
.prepare(:first, statement_id(:hstore_load))
|
197
197
|
end
|
198
198
|
|
199
199
|
def prepare_delete
|
200
|
-
@delete = @table.where(key_column => :$row)
|
201
|
-
.prepare(:update, statement_id(:hstore_delete), value_column => ::Sequel[value_column].hstore.delete(:$key))
|
200
|
+
@delete = @table.where(config.key_column => :$row)
|
201
|
+
.prepare(:update, statement_id(:hstore_delete), config.value_column => ::Sequel[config.value_column].hstore.delete(:$key))
|
202
202
|
end
|
203
203
|
|
204
204
|
def prepare_create
|
@@ -207,30 +207,30 @@ module Moneta
|
|
207
207
|
# https://stackoverflow.com/questions/11940401/escaping-hstore-contains-operators-in-a-jdbc-prepared-statement
|
208
208
|
return if defined?(JRUBY_VERSION)
|
209
209
|
@create = @table
|
210
|
-
.where(key_column => :$row)
|
211
|
-
.exclude(::Sequel[value_column].hstore.key?(:$key))
|
212
|
-
.prepare(:update, statement_id(:hstore_create), value_column => ::Sequel[value_column].hstore.merge(:$pair))
|
210
|
+
.where(config.key_column => :$row)
|
211
|
+
.exclude(::Sequel[config.value_column].hstore.key?(:$key))
|
212
|
+
.prepare(:update, statement_id(:hstore_create), config.value_column => ::Sequel[config.value_column].hstore.merge(:$pair))
|
213
213
|
end
|
214
214
|
|
215
215
|
def prepare_values_at
|
216
216
|
@values_at = @table
|
217
|
-
.where(key_column => :$row)
|
218
|
-
.select(::Sequel[value_column].hstore[::Sequel.cast(:$keys, :"text[]")].as(:values))
|
217
|
+
.where(config.key_column => :$row)
|
218
|
+
.select(::Sequel[config.value_column].hstore[::Sequel.cast(:$keys, :"text[]")].as(:values))
|
219
219
|
.prepare(:first, statement_id(:hstore_values_at))
|
220
220
|
end
|
221
221
|
|
222
222
|
def prepare_slice
|
223
223
|
slice = @table
|
224
|
-
.where(key_column => :$row)
|
225
|
-
.select(::Sequel[value_column].hstore.slice(:$keys).as(:pairs))
|
224
|
+
.where(config.key_column => :$row)
|
225
|
+
.select(::Sequel[config.value_column].hstore.slice(:$keys).as(:pairs))
|
226
226
|
@slice = slice.prepare(:first, statement_id(:hstore_slice))
|
227
227
|
@slice_for_update = slice.for_update.prepare(:first, statement_id(:hstore_slice_for_update))
|
228
228
|
end
|
229
229
|
|
230
230
|
def prepare_size
|
231
231
|
@size = @backend
|
232
|
-
.from(@table.where(key_column => :$row)
|
233
|
-
|
232
|
+
.from(@table.where(config.key_column => :$row)
|
233
|
+
.select(::Sequel[config.value_column].hstore.each))
|
234
234
|
.select { count.function.*.as(:size) }
|
235
235
|
.prepare(:first, statement_id(:hstore_size))
|
236
236
|
end
|
@@ -10,7 +10,7 @@ module Moneta
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def store(key, value, options = {})
|
13
|
-
@table.insert_conflict(:replace).insert(key_column => key, value_column => blob(value))
|
13
|
+
@table.insert_conflict(:replace).insert(config.key_column => key, config.value_column => blob(value))
|
14
14
|
value
|
15
15
|
end
|
16
16
|
|
@@ -25,7 +25,7 @@ module Moneta
|
|
25
25
|
def merge!(pairs, options = {}, &block)
|
26
26
|
@backend.transaction do
|
27
27
|
pairs = yield_merge_pairs(pairs, &block) if block_given?
|
28
|
-
@table.insert_conflict(:replace).import([key_column, value_column], blob_pairs(pairs).to_a)
|
28
|
+
@table.insert_conflict(:replace).import([config.key_column, config.value_column], blob_pairs(pairs).to_a)
|
29
29
|
end
|
30
30
|
|
31
31
|
self
|
@@ -36,20 +36,20 @@ module Moneta
|
|
36
36
|
def prepare_store
|
37
37
|
@store = @table
|
38
38
|
.insert_conflict(:replace)
|
39
|
-
.prepare(:insert, statement_id(:store), key_column => :$key, value_column => :$value)
|
39
|
+
.prepare(:insert, statement_id(:store), config.key_column => :$key, config.value_column => :$value)
|
40
40
|
end
|
41
41
|
|
42
42
|
def prepare_increment
|
43
43
|
return super unless @can_upsert
|
44
|
-
update_expr = (::Sequel[value_column].cast(Integer) + :$amount).cast(:blob)
|
44
|
+
update_expr = (::Sequel[config.value_column].cast(Integer) + :$amount).cast(:blob)
|
45
45
|
@increment = @table
|
46
46
|
.insert_conflict(
|
47
|
-
target: key_column,
|
48
|
-
update: { value_column => update_expr },
|
49
|
-
update_where: ::Sequel.|({ value_column => blob("0") },
|
50
|
-
{ ::Sequel.~(::Sequel[value_column].cast(Integer)) => 0 })
|
47
|
+
target: config.key_column,
|
48
|
+
update: { config.value_column => update_expr },
|
49
|
+
update_where: ::Sequel.|({ config.value_column => blob("0") },
|
50
|
+
{ ::Sequel.~(::Sequel[config.value_column].cast(Integer)) => 0 })
|
51
51
|
)
|
52
|
-
.prepare(:insert, statement_id(:increment), key_column => :$key, value_column => :$value)
|
52
|
+
.prepare(:insert, statement_id(:increment), config.key_column => :$key, config.value_column => :$value)
|
53
53
|
end
|
54
54
|
end
|
55
55
|
end
|