dbee-active_record 2.1.0.pre.alpha → 2.1.0.pre.alpha.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f8de8c388637ba455ffca406ff42751ecfb62f4a40bbcb9f560a085b585568a1
4
- data.tar.gz: 9723886e37e886d7df7fa4661df4c81d35fe186d08a7d82de66083e08ed44bac
3
+ metadata.gz: 75d42ea7f3b391ad5014264a4b914339bf7dff8582aebe85c4c3180576ae7648
4
+ data.tar.gz: e63553d0dcc906a38b336767dfcf10bcc162807682ae866f4450a80185993b8e
5
5
  SHA512:
6
- metadata.gz: be75ae14b3c4b0154a0cc4f63950fa86a5f9f16272cd2d5133a4fc4649e2bcd6f7dc5836cf1706c7a9a6b9dba1f1183783038b013bc9e78f5cc5f25e9c980f78
7
- data.tar.gz: 7f466202c164f0da7fb936010bc73393a0643682588f14093979fa1e8844f36bd0978020f3f435624d6bea25d95767af35884c6e453a35f41d219dd4331b22d7
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
- values = normalize(filter.value)
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
- if filter.is_a?(Query::Filters::Equals) && values.length > 1
22
- arel_column.in(values)
23
- elsif filter.is_a?(Query::Filters::NotEquals) && values.length > 1
24
- arel_column.not_in(values)
25
- else
26
- use_or(filter, arel_column)
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 normalize(value)
48
- value ? Array(value).flatten : [nil]
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 use_or(filter, arel_column)
52
- predicates = normalize(filter.value).map do |coerced_value|
53
- method = FILTER_EVALUATORS[filter.class]
62
+ def use_in?(filter, values)
63
+ filter.is_a?(Query::Filters::Equals) && values.length > 1
64
+ end
54
65
 
55
- raise ArgumentError, "cannot compile filter: #{filter}" unless method
66
+ def use_not_in?(filter, values)
67
+ filter.is_a?(Query::Filters::NotEquals) && values.length > 1
68
+ end
56
69
 
57
- method.call(arel_column, coerced_value)
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
- predicates.inject(predicates.shift) do |memo, predicate|
61
- memo.or(predicate)
62
- end
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
@@ -10,7 +10,7 @@
10
10
  module Dbee
11
11
  module Providers
12
12
  class ActiveRecordProvider
13
- VERSION = '2.1.0-alpha'
13
+ VERSION = '2.1.0-alpha.1'
14
14
  end
15
15
  end
16
16
  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', NULL) AND
71
- "theaters"."inspected" IN ('f', 't', NULL) AND
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', NULL) AND
89
- "t0"."inspected" IN ('f', 't', NULL) AND
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, NULL) AND
107
- `theaters`.`inspected` IN (FALSE, TRUE, NULL) AND
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, NULL) AND
125
- `t0`.`inspected` IN (FALSE, TRUE, NULL) AND
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-03 00:00:00.000000000 Z
11
+ date: 2020-07-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord