dbee-active_record 2.1.0.pre.alpha → 2.1.0.pre.alpha.1
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 75d42ea7f3b391ad5014264a4b914339bf7dff8582aebe85c4c3180576ae7648
|
4
|
+
data.tar.gz: e63553d0dcc906a38b336767dfcf10bcc162807682ae866f4450a80185993b8e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f727e65305615a6e5b2450654ce4bb174674970be4b6855922035dac6bc8378862a003f0c1ec4677433d560dee4f5ca3b9094b57a4be8eae6a7d78720c805910
|
7
|
+
data.tar.gz: 21d91630d8ba8407550dcdd6d8a7aab9bc7dc52ad39679ed5b673f59263f2761e55505c61b8cafcc2ce09a31fee1571e58e9fffc76b24f1dd7a5d3d62e3b4ef7
|
@@ -16,14 +16,19 @@ module Dbee
|
|
16
16
|
include Singleton
|
17
17
|
|
18
18
|
def make(filter, arel_column)
|
19
|
-
|
19
|
+
# If the filter has a value of nil, then simply return an IS NULL predicate
|
20
|
+
return make_is_null_predicate(arel_column) unless filter.value
|
20
21
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
22
|
+
values = Array(filter.value).flatten
|
23
|
+
|
24
|
+
# This logic helps ensure that if a null exists that it translates to an IS NULL
|
25
|
+
# predicate and does not get put into an in or not_in clause.
|
26
|
+
predicates = values.include?(nil) ? [make_is_null_predicate(arel_column)] : []
|
27
|
+
predicates += make_predicates(filter, arel_column, values - [nil])
|
28
|
+
|
29
|
+
# Chain all predicates together
|
30
|
+
predicates.inject(predicates.shift) do |memo, predicate|
|
31
|
+
memo.or(predicate)
|
27
32
|
end
|
28
33
|
end
|
29
34
|
|
@@ -44,22 +49,40 @@ module Dbee
|
|
44
49
|
|
45
50
|
private_constant :FILTER_EVALUATORS
|
46
51
|
|
47
|
-
def
|
48
|
-
|
52
|
+
def make_predicates(filter, arel_column, values)
|
53
|
+
if use_in?(filter, values)
|
54
|
+
[arel_column.in(values)]
|
55
|
+
elsif use_not_in?(filter, values)
|
56
|
+
[arel_column.not_in(values)]
|
57
|
+
else
|
58
|
+
make_or_predicates(filter, arel_column, values)
|
59
|
+
end
|
49
60
|
end
|
50
61
|
|
51
|
-
def
|
52
|
-
|
53
|
-
|
62
|
+
def use_in?(filter, values)
|
63
|
+
filter.is_a?(Query::Filters::Equals) && values.length > 1
|
64
|
+
end
|
54
65
|
|
55
|
-
|
66
|
+
def use_not_in?(filter, values)
|
67
|
+
filter.is_a?(Query::Filters::NotEquals) && values.length > 1
|
68
|
+
end
|
56
69
|
|
57
|
-
|
70
|
+
def make_or_predicates(filter, arel_column, values)
|
71
|
+
values.map do |value|
|
72
|
+
make_predicate(arel_column, filter.class, value)
|
58
73
|
end
|
74
|
+
end
|
59
75
|
|
60
|
-
|
61
|
-
|
62
|
-
|
76
|
+
def make_predicate(arel_column, filter_class, value)
|
77
|
+
method = FILTER_EVALUATORS[filter_class]
|
78
|
+
|
79
|
+
raise ArgumentError, "cannot compile filter: #{filter}" unless method
|
80
|
+
|
81
|
+
method.call(arel_column, value)
|
82
|
+
end
|
83
|
+
|
84
|
+
def make_is_null_predicate(arel_column)
|
85
|
+
make_predicate(arel_column, Query::Filters::Equals, nil)
|
63
86
|
end
|
64
87
|
end
|
65
88
|
end
|
@@ -67,8 +67,8 @@ sqlite_readable: |+
|
|
67
67
|
"theaters"."name" LIKE 'A%' AND
|
68
68
|
"theaters"."name" LIKE '%m%' AND
|
69
69
|
"theaters"."active" = 'false' AND
|
70
|
-
"theaters"."active" IN ('t', 'f'
|
71
|
-
"theaters"."inspected" IN ('f', 't'
|
70
|
+
("theaters"."active" IS NULL OR "theaters"."active" IN ('t', 'f')) AND
|
71
|
+
("theaters"."inspected" IS NULL OR "theaters"."inspected" IN ('f', 't')) AND
|
72
72
|
"theaters"."created_at" <= '2019-03-04' AND
|
73
73
|
"theaters"."created_at" < '2018-03-04' AND
|
74
74
|
"theaters"."created_at" >= '2001-03-04' AND
|
@@ -85,8 +85,8 @@ sqlite_not_readable: |+
|
|
85
85
|
"t0"."name" LIKE 'A%' AND
|
86
86
|
"t0"."name" LIKE '%m%' AND
|
87
87
|
"t0"."active" = 'false' AND
|
88
|
-
"t0"."active" IN ('t', 'f'
|
89
|
-
"t0"."inspected" IN ('f', 't'
|
88
|
+
("t0"."active" IS NULL OR "t0"."active" IN ('t', 'f')) AND
|
89
|
+
("t0"."inspected" IS NULL OR "t0"."inspected" IN ('f', 't')) AND
|
90
90
|
"t0"."created_at" <= '2019-03-04' AND
|
91
91
|
"t0"."created_at" < '2018-03-04' AND
|
92
92
|
"t0"."created_at" >= '2001-03-04' AND
|
@@ -103,8 +103,8 @@ mysql_readable: |+
|
|
103
103
|
`theaters`.`name` LIKE 'A%' AND
|
104
104
|
`theaters`.`name` LIKE '%m%' AND
|
105
105
|
`theaters`.`active` = 'false' AND
|
106
|
-
`theaters`.`active` IN (TRUE, FALSE
|
107
|
-
`theaters`.`inspected` IN (FALSE, TRUE
|
106
|
+
(`theaters`.`active` IS NULL OR `theaters`.`active` IN (TRUE, FALSE)) AND
|
107
|
+
(`theaters`.`inspected` IS NULL OR `theaters`.`inspected` IN (FALSE, TRUE)) AND
|
108
108
|
`theaters`.`created_at` <= '2019-03-04' AND
|
109
109
|
`theaters`.`created_at` < '2018-03-04' AND
|
110
110
|
`theaters`.`created_at` >= '2001-03-04' AND
|
@@ -121,8 +121,8 @@ mysql_not_readable: |+
|
|
121
121
|
`t0`.`name` LIKE 'A%' AND
|
122
122
|
`t0`.`name` LIKE '%m%' AND
|
123
123
|
`t0`.`active` = 'false' AND
|
124
|
-
`t0`.`active` IN (TRUE, FALSE
|
125
|
-
`t0`.`inspected` IN (FALSE, TRUE
|
124
|
+
(`t0`.`active` IS NULL OR `t0`.`active` IN (TRUE, FALSE)) AND
|
125
|
+
(`t0`.`inspected` IS NULL OR `t0`.`inspected` IN (FALSE, TRUE)) AND
|
126
126
|
`t0`.`created_at` <= '2019-03-04' AND
|
127
127
|
`t0`.`created_at` < '2018-03-04' AND
|
128
128
|
`t0`.`created_at` >= '2001-03-04' AND
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dbee-active_record
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.1.0.pre.alpha
|
4
|
+
version: 2.1.0.pre.alpha.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matthew Ruggio
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-07-
|
11
|
+
date: 2020-07-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|