simple-sql 0.5.26 → 0.5.27
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/VERSION +1 -1
- data/lib/simple/sql/connection/scope/search.rb +7 -1
- data/spec/simple/sql/search_spec.rb +5 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fd927c6b8b525593892421de3ce43fefa20d036c3d3eaf3ee3f0bbb863108deb
|
4
|
+
data.tar.gz: 2765ce9e6f3e86801074b014f142a607673f04692c6b0d8d3424c024066f25c9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b4737e323e981525a17129dfdfd1e5a8076e99350ae0f758d6e5d53386ecd57e8d1c66766dbf8ded98b6fdf14ca25ee5a2a616b6c3ae04b844917d71f2ad720a
|
7
|
+
data.tar.gz: 8a86b32006f6bf1713c71550ea4a32bf4c393558ec8d76738d9905cae114bb470404c5168c10b352b5394b2ea7230277b931089cea9f15110e04522cb279cd5c
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.5.
|
1
|
+
0.5.27
|
@@ -75,6 +75,12 @@ module Simple::SQL::Connection::Scope::Search
|
|
75
75
|
|
76
76
|
# -- apply dynamic filters --------------------------------------------------
|
77
77
|
|
78
|
+
def empty_filter?(_key, value)
|
79
|
+
return true if value.nil?
|
80
|
+
return true if value.is_a?(Enumerable) && value.empty? # i.e. Hash, Array
|
81
|
+
false
|
82
|
+
end
|
83
|
+
|
78
84
|
def apply_dynamic_filters(scope, filters, dynamic_column:)
|
79
85
|
# we translate a condition of "foo => []" into a SQL fragment like this:
|
80
86
|
#
|
@@ -82,7 +88,7 @@ module Simple::SQL::Connection::Scope::Search
|
|
82
88
|
#
|
83
89
|
# i.e. we check for non-existing columns and columns that exist but have a
|
84
90
|
# value of null (i.e. column->'key' IS NULL).
|
85
|
-
empty_filters, filters = filters.partition { |
|
91
|
+
empty_filters, filters = filters.partition { |key, value| empty_filter?(key, value) }
|
86
92
|
empty_filters.each do |key, _|
|
87
93
|
scope = scope.where("(NOT #{dynamic_column} ? '#{key}' OR #{dynamic_column} @> '#{::JSON.generate(key => nil)}'::jsonb)")
|
88
94
|
end
|
@@ -20,10 +20,14 @@ describe "Simple::SQL.search" do
|
|
20
20
|
scope.search(*args).all
|
21
21
|
end
|
22
22
|
|
23
|
-
it "filters by one dynamic attribute
|
23
|
+
it "filters by one dynamic attribute matching a String" do
|
24
24
|
expect(search(even_str: "yes").map(&:id)).to contain_exactly(2,4,6,8,10)
|
25
25
|
end
|
26
26
|
|
27
|
+
it "filters by one dynamic attribute matching an Integer" do
|
28
|
+
expect(search(user_id_squared: 4).map(&:id)).to contain_exactly(2)
|
29
|
+
end
|
30
|
+
|
27
31
|
it "filters by one dynamic attribute and multiple matches" do
|
28
32
|
expect(search(user_id_squared: [1, 3, 9]).map(&:id)).to contain_exactly(1,3)
|
29
33
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple-sql
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.27
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- radiospiel
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2020-01-
|
12
|
+
date: 2020-01-22 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: pg_array_parser
|