superstore 2.2.0 → 2.3.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 +4 -4
- data/.travis.yml +20 -6
- data/CHANGELOG.md +8 -0
- data/Rakefile +2 -5
- data/lib/superstore/adapters/jsonb_adapter.rb +4 -60
- data/superstore.gemspec +1 -1
- data/test/support/jsonb.rb +0 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: efa28ad8771bdcf6a918cf33a4d81f3e6945581a
|
4
|
+
data.tar.gz: 732be1d35bf085bc141c1772d7beef1e1655f397
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c8f18bbcabe090e89e0ff5a19058689b7e2002488be9332c666e62cc556e78a58573918e27081c48f13eb9ed30c26a60cab90d6c39abe0f0e2522f6e90770786
|
7
|
+
data.tar.gz: bfc9b5f6637f4955ad45753f0a2996be1f5892aba8ac15646ee9deb4194237b2300c1d57ef42c22e310f8e6e261aedc7c75bcdca58fc40a5fad36395a0f2c0da
|
data/.travis.yml
CHANGED
@@ -1,9 +1,23 @@
|
|
1
1
|
language: ruby
|
2
2
|
rvm:
|
3
|
-
- 2.
|
4
|
-
- 2.
|
5
|
-
- 2.
|
6
|
-
sudo:
|
3
|
+
- 2.1.10
|
4
|
+
- 2.2.5
|
5
|
+
- 2.3.1
|
6
|
+
sudo: required
|
7
|
+
dist: trusty
|
7
8
|
cache: bundler
|
8
|
-
|
9
|
-
|
9
|
+
before_install:
|
10
|
+
# https://github.com/travis-ci/travis-ci/issues/4264
|
11
|
+
- sudo cp /etc/postgresql/9.4/main/pg_hba.conf /tmp
|
12
|
+
- sudo add-apt-repository "deb http://apt.postgresql.org/pub/repos/apt/ $(lsb_release -cs)-pgdg 9.5"
|
13
|
+
- sudo apt-key adv --keyserver keys.gnupg.net --recv-keys 7FCC7D46ACCC4CF8
|
14
|
+
- sudo apt-get update
|
15
|
+
- sudo service postgresql stop
|
16
|
+
- for version in 9.1 9.2 9.3 9.4; do sudo pg_dropcluster --stop $version main; done
|
17
|
+
- sudo apt-get remove --purge --yes postgresql-9.[1234]
|
18
|
+
- sudo apt-get install --no-install-recommends --yes postgresql-client-9.5 postgresql-9.5
|
19
|
+
- sudo apt-get autoremove --yes
|
20
|
+
- sudo cp /tmp/pg_hba.conf /etc/postgresql/9.5/main/
|
21
|
+
- sudo service postgresql restart
|
22
|
+
- sudo -u postgres createuser -s travis
|
23
|
+
- sudo -u postgres createdb -O travis travis
|
data/CHANGELOG.md
CHANGED
data/Rakefile
CHANGED
@@ -1,12 +1,9 @@
|
|
1
|
-
require 'bundler/
|
2
|
-
require 'rake'
|
1
|
+
require 'bundler/gem_tasks'
|
3
2
|
require 'rake/testtask'
|
4
3
|
|
5
4
|
task default: :test
|
6
5
|
|
7
6
|
Rake::TestTask.new(:test) do |t|
|
8
|
-
t.libs
|
9
|
-
t.libs << 'test'
|
7
|
+
t.libs = %w(lib test)
|
10
8
|
t.pattern = 'test/unit/**/*_test.rb'
|
11
|
-
t.verbose = true
|
12
9
|
end
|
@@ -30,7 +30,8 @@ module Superstore
|
|
30
30
|
elsif @scope.select_values == [@adapter.primary_key_column]
|
31
31
|
@adapter.primary_key_column
|
32
32
|
else
|
33
|
-
"#{@adapter.
|
33
|
+
selects = @scope.select_values.map { |key| "#{@adapter.quote(key)},document->>#{@adapter.quote(key)}" }
|
34
|
+
"#{@adapter.primary_key_column}, json_build_object(#{selects * ','}) as document"
|
34
35
|
end
|
35
36
|
end
|
36
37
|
|
@@ -142,18 +143,9 @@ module Superstore
|
|
142
143
|
def update(table, id, attributes)
|
143
144
|
return if attributes.empty?
|
144
145
|
|
145
|
-
|
146
|
-
nil_attributes = attributes.select { |key, value| value.nil? }
|
147
|
-
|
148
|
-
if not_nil_attributes.any? && nil_attributes.any?
|
149
|
-
value_update = "jsonb_merge(jsonb_delete(document, #{fields_to_postgres_array(nil_attributes.keys)}), #{to_quoted_jsonb(not_nil_attributes)})"
|
150
|
-
elsif not_nil_attributes.any?
|
151
|
-
value_update = "jsonb_merge(document, #{to_quoted_jsonb(not_nil_attributes)})"
|
152
|
-
elsif nil_attributes.any?
|
153
|
-
value_update = "jsonb_delete(document, #{fields_to_postgres_array(nil_attributes.keys)})"
|
154
|
-
end
|
155
|
-
|
146
|
+
value_update = "jsonb_strip_nulls(document || #{to_quoted_jsonb(attributes)})"
|
156
147
|
statement = "UPDATE #{table} SET document = #{value_update} WHERE #{primary_key_column} = #{quote(id)}"
|
148
|
+
|
157
149
|
execute_batchable statement
|
158
150
|
end
|
159
151
|
|
@@ -205,54 +197,6 @@ module Superstore
|
|
205
197
|
def to_quoted_jsonb(data)
|
206
198
|
"#{quote(Oj.dump(data, OJ_OPTIONS))}::JSONB"
|
207
199
|
end
|
208
|
-
|
209
|
-
JSON_FUNCTIONS = {
|
210
|
-
# SELECT jsonb_slice('{"b": 2, "c": 3, "a": 4}', '{b, c}');
|
211
|
-
'jsonb_slice(data jsonb, keys text[])' => %{
|
212
|
-
SELECT json_object_agg(key, value)::jsonb
|
213
|
-
FROM (
|
214
|
-
SELECT * FROM jsonb_each(data)
|
215
|
-
) t
|
216
|
-
WHERE key =ANY(keys);
|
217
|
-
},
|
218
|
-
|
219
|
-
# SELECT jsonb_merge('{"a": 1}', '{"b": 2, "c": 3, "a": 4}');
|
220
|
-
'jsonb_merge(data jsonb, merge_data jsonb)' => %{
|
221
|
-
SELECT json_object_agg(key, value)::jsonb
|
222
|
-
FROM (
|
223
|
-
WITH to_merge AS (
|
224
|
-
SELECT * FROM jsonb_each(merge_data)
|
225
|
-
)
|
226
|
-
SELECT *
|
227
|
-
FROM jsonb_each(data)
|
228
|
-
WHERE key NOT IN (SELECT key FROM to_merge)
|
229
|
-
UNION ALL
|
230
|
-
SELECT * FROM to_merge
|
231
|
-
) t;
|
232
|
-
},
|
233
|
-
|
234
|
-
# SELECT jsonb_delete('{"b": 2, "c": 3, "a": 4}', '{b, c}');
|
235
|
-
'jsonb_delete(data jsonb, keys text[])' => %{
|
236
|
-
SELECT json_object_agg(key, value)::jsonb
|
237
|
-
FROM (
|
238
|
-
SELECT * FROM jsonb_each(data)
|
239
|
-
WHERE key <>ALL(keys)
|
240
|
-
) t;
|
241
|
-
},
|
242
|
-
}
|
243
|
-
def define_jsonb_functions!
|
244
|
-
JSON_FUNCTIONS.each do |signature, body|
|
245
|
-
connection.execute %{
|
246
|
-
CREATE OR REPLACE FUNCTION public.#{signature}
|
247
|
-
RETURNS jsonb
|
248
|
-
IMMUTABLE
|
249
|
-
LANGUAGE sql
|
250
|
-
AS $$
|
251
|
-
#{body}
|
252
|
-
$$;
|
253
|
-
}
|
254
|
-
end
|
255
|
-
end
|
256
200
|
end
|
257
201
|
end
|
258
202
|
end
|
data/superstore.gemspec
CHANGED
data/test/support/jsonb.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: superstore
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Koziarski
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2016-06-
|
12
|
+
date: 2016-06-29 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activemodel
|