query_helper 0.2.14 → 0.2.19
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +30 -30
- data/lib/query_helper.rb +27 -27
- data/lib/query_helper/column_map.rb +1 -1
- data/lib/query_helper/version.rb +1 -1
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c3bc15fea354655ec8dc8ab74e84849104d7f13e8f0dfc064d7210d75642ae60
|
4
|
+
data.tar.gz: cdb0d638c3afc722e19816d136a1a27f5716e1d06bc838eeea481d6995438f7c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4ce4101f690100aabd91841e8866daa1bffc728d5b741739707dc28bdb220dc2851974fb468d11ad5c681d5aa3315c49e93e3de7b197046e4badfd8bdb339866
|
7
|
+
data.tar.gz: 65aaa2d1e2d37ae994968728df34027cd846ff4e38c6c25771c64c90bffde48d799fb70ddffdadbee7b6a7584055e2ba8a43a32155a2aff1e2e0c6311c98261d
|
data/Gemfile.lock
CHANGED
@@ -1,56 +1,56 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
query_helper (0.2.
|
4
|
+
query_helper (0.2.19)
|
5
5
|
activerecord (> 5)
|
6
6
|
activesupport (> 5)
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: https://rubygems.org/
|
10
10
|
specs:
|
11
|
-
actionpack (6.0.
|
12
|
-
actionview (= 6.0.
|
13
|
-
activesupport (= 6.0.
|
11
|
+
actionpack (6.0.3.2)
|
12
|
+
actionview (= 6.0.3.2)
|
13
|
+
activesupport (= 6.0.3.2)
|
14
14
|
rack (~> 2.0, >= 2.0.8)
|
15
15
|
rack-test (>= 0.6.3)
|
16
16
|
rails-dom-testing (~> 2.0)
|
17
17
|
rails-html-sanitizer (~> 1.0, >= 1.2.0)
|
18
|
-
actionview (6.0.
|
19
|
-
activesupport (= 6.0.
|
18
|
+
actionview (6.0.3.2)
|
19
|
+
activesupport (= 6.0.3.2)
|
20
20
|
builder (~> 3.1)
|
21
21
|
erubi (~> 1.4)
|
22
22
|
rails-dom-testing (~> 2.0)
|
23
23
|
rails-html-sanitizer (~> 1.1, >= 1.2.0)
|
24
|
-
activemodel (6.0.
|
25
|
-
activesupport (= 6.0.
|
26
|
-
activerecord (6.0.
|
27
|
-
activemodel (= 6.0.
|
28
|
-
activesupport (= 6.0.
|
29
|
-
activesupport (6.0.
|
24
|
+
activemodel (6.0.3.2)
|
25
|
+
activesupport (= 6.0.3.2)
|
26
|
+
activerecord (6.0.3.2)
|
27
|
+
activemodel (= 6.0.3.2)
|
28
|
+
activesupport (= 6.0.3.2)
|
29
|
+
activesupport (6.0.3.2)
|
30
30
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
31
31
|
i18n (>= 0.7, < 2)
|
32
32
|
minitest (~> 5.1)
|
33
33
|
tzinfo (~> 1.1)
|
34
|
-
zeitwerk (~> 2.2)
|
34
|
+
zeitwerk (~> 2.2, >= 2.2.2)
|
35
35
|
builder (3.2.4)
|
36
|
-
byebug (11.1.
|
36
|
+
byebug (11.1.3)
|
37
37
|
concurrent-ruby (1.1.6)
|
38
38
|
crass (1.0.6)
|
39
|
-
diff-lcs (1.
|
39
|
+
diff-lcs (1.4.4)
|
40
40
|
erubi (1.9.0)
|
41
41
|
faker (1.9.6)
|
42
42
|
i18n (>= 0.7)
|
43
|
-
i18n (1.8.
|
43
|
+
i18n (1.8.5)
|
44
44
|
concurrent-ruby (~> 1.0)
|
45
|
-
loofah (2.
|
45
|
+
loofah (2.6.0)
|
46
46
|
crass (~> 1.0.2)
|
47
47
|
nokogiri (>= 1.5.9)
|
48
48
|
method_source (1.0.0)
|
49
49
|
mini_portile2 (2.4.0)
|
50
|
-
minitest (5.14.
|
51
|
-
nokogiri (1.10.
|
50
|
+
minitest (5.14.1)
|
51
|
+
nokogiri (1.10.10)
|
52
52
|
mini_portile2 (~> 2.4.0)
|
53
|
-
rack (2.2.
|
53
|
+
rack (2.2.3)
|
54
54
|
rack-test (1.1.0)
|
55
55
|
rack (>= 1.0, < 3)
|
56
56
|
rails-dom-testing (2.0.3)
|
@@ -58,9 +58,9 @@ GEM
|
|
58
58
|
nokogiri (>= 1.6)
|
59
59
|
rails-html-sanitizer (1.3.0)
|
60
60
|
loofah (~> 2.3)
|
61
|
-
railties (6.0.
|
62
|
-
actionpack (= 6.0.
|
63
|
-
activesupport (= 6.0.
|
61
|
+
railties (6.0.3.2)
|
62
|
+
actionpack (= 6.0.3.2)
|
63
|
+
activesupport (= 6.0.3.2)
|
64
64
|
method_source
|
65
65
|
rake (>= 0.8.7)
|
66
66
|
thor (>= 0.20.3, < 2.0)
|
@@ -69,15 +69,15 @@ GEM
|
|
69
69
|
rspec-core (~> 3.9.0)
|
70
70
|
rspec-expectations (~> 3.9.0)
|
71
71
|
rspec-mocks (~> 3.9.0)
|
72
|
-
rspec-core (3.9.
|
73
|
-
rspec-support (~> 3.9.
|
74
|
-
rspec-expectations (3.9.
|
72
|
+
rspec-core (3.9.2)
|
73
|
+
rspec-support (~> 3.9.3)
|
74
|
+
rspec-expectations (3.9.2)
|
75
75
|
diff-lcs (>= 1.2.0, < 2.0)
|
76
76
|
rspec-support (~> 3.9.0)
|
77
77
|
rspec-mocks (3.9.1)
|
78
78
|
diff-lcs (>= 1.2.0, < 2.0)
|
79
79
|
rspec-support (~> 3.9.0)
|
80
|
-
rspec-rails (4.0.
|
80
|
+
rspec-rails (4.0.1)
|
81
81
|
actionpack (>= 4.2)
|
82
82
|
activesupport (>= 4.2)
|
83
83
|
railties (>= 4.2)
|
@@ -85,13 +85,13 @@ GEM
|
|
85
85
|
rspec-expectations (~> 3.9)
|
86
86
|
rspec-mocks (~> 3.9)
|
87
87
|
rspec-support (~> 3.9)
|
88
|
-
rspec-support (3.9.
|
88
|
+
rspec-support (3.9.3)
|
89
89
|
sqlite3 (1.3.13)
|
90
90
|
thor (1.0.1)
|
91
91
|
thread_safe (0.3.6)
|
92
|
-
tzinfo (1.2.
|
92
|
+
tzinfo (1.2.7)
|
93
93
|
thread_safe (~> 0.1)
|
94
|
-
zeitwerk (2.
|
94
|
+
zeitwerk (2.4.0)
|
95
95
|
|
96
96
|
PLATFORMS
|
97
97
|
ruby
|
data/lib/query_helper.rb
CHANGED
@@ -80,13 +80,13 @@ class QueryHelper
|
|
80
80
|
@as_json_options = as_json_options if as_json_options
|
81
81
|
@custom_mappings = custom_mappings if custom_mappings
|
82
82
|
@preload = preload if preload
|
83
|
-
@search_fields = search_fields if search_fields
|
84
|
-
@sql_filter = sql_filter if sql_filter
|
85
|
-
@sql_sort = sql_sort if sql_sort
|
86
|
-
@search_string = search_string if search_string
|
83
|
+
@search_fields = search_fields if search_fields
|
84
|
+
@sql_filter = sql_filter if sql_filter
|
85
|
+
@sql_sort = sql_sort if sql_sort
|
86
|
+
@search_string = search_string if search_string
|
87
87
|
@page = determine_page(page: page, per_page: per_page) if page
|
88
88
|
@per_page = determine_per_page(page: page, per_page: per_page) if per_page
|
89
|
-
@metadata = metadata if metadata
|
89
|
+
@metadata = metadata if metadata
|
90
90
|
set_limit_and_offset()
|
91
91
|
return self
|
92
92
|
end
|
@@ -116,21 +116,21 @@ class QueryHelper
|
|
116
116
|
@sql_filter.create_filters()
|
117
117
|
|
118
118
|
having_clauses = @sql_filter.having_clauses
|
119
|
-
where_clauses = @sql_filter.where_clauses
|
120
|
-
|
119
|
+
where_clauses = @sql_filter.where_clauses
|
120
|
+
|
121
121
|
if @search_string
|
122
122
|
search_filter = search_filter(column_maps)
|
123
123
|
if search_filter[:placement] == :where
|
124
124
|
where_clauses << search_filter[:filter]
|
125
|
-
else
|
125
|
+
else
|
126
126
|
having_clauses << search_filter[:filter]
|
127
127
|
end
|
128
|
-
end
|
128
|
+
end
|
129
129
|
|
130
130
|
|
131
131
|
# merge the filter bind variables into the query bind variables
|
132
132
|
@bind_variables.merge!(@sql_filter.bind_variables)
|
133
|
-
|
133
|
+
|
134
134
|
# Execute Sql Query
|
135
135
|
manipulator = SqlManipulator.new(
|
136
136
|
sql: @query,
|
@@ -144,7 +144,7 @@ class QueryHelper
|
|
144
144
|
end
|
145
145
|
|
146
146
|
def to_json(args)
|
147
|
-
|
147
|
+
results.to_json
|
148
148
|
end
|
149
149
|
|
150
150
|
def to_sql
|
@@ -152,7 +152,7 @@ class QueryHelper
|
|
152
152
|
return query if @bind_variables.length == 0
|
153
153
|
begin
|
154
154
|
return @model.sanitize_sql_array([query, @bind_variables])
|
155
|
-
rescue NoMethodError
|
155
|
+
rescue NoMethodError
|
156
156
|
# sanitize_sql_array is a protected method before Rails v5.2.3
|
157
157
|
return @model.send(:sanitize_sql_array, [query, @bind_variables])
|
158
158
|
end
|
@@ -181,14 +181,14 @@ class QueryHelper
|
|
181
181
|
|
182
182
|
def pagination_results(count=@count)
|
183
183
|
# Set pagination params if they aren't provided
|
184
|
-
results_per_page = @per_page || count
|
185
|
-
results_page = @page || 1
|
184
|
+
results_per_page = @per_page || count
|
185
|
+
results_page = @page || 1
|
186
186
|
|
187
|
-
total_pages = (count/(results_per_page.nonzero? || 1).to_f).ceil
|
187
|
+
total_pages = (count.to_i/(results_per_page.nonzero? || 1).to_f).ceil
|
188
188
|
next_page = results_page + 1 if results_page.between?(1, total_pages - 1)
|
189
189
|
previous_page = results_page - 1 if results_page.between?(2, total_pages)
|
190
190
|
first_page = results_page == 1
|
191
|
-
last_page = results_page
|
191
|
+
last_page = results_page >= total_pages
|
192
192
|
out_of_range = !results_page.between?(1,total_pages)
|
193
193
|
|
194
194
|
{ count: count,
|
@@ -205,16 +205,16 @@ class QueryHelper
|
|
205
205
|
private
|
206
206
|
|
207
207
|
def determine_page(page:, per_page:)
|
208
|
-
return page.to_i if page
|
209
|
-
return 1 if !page && per_page
|
208
|
+
return page.to_i if page
|
209
|
+
return 1 if !page && per_page
|
210
210
|
return nil
|
211
|
-
end
|
211
|
+
end
|
212
212
|
|
213
213
|
def determine_per_page(page:, per_page:)
|
214
|
-
return per_page.to_i if per_page
|
215
|
-
return 100 if !per_page && page
|
214
|
+
return per_page.to_i if per_page
|
215
|
+
return 100 if !per_page && page
|
216
216
|
return nil
|
217
|
-
end
|
217
|
+
end
|
218
218
|
|
219
219
|
def set_limit_and_offset
|
220
220
|
if @page && @per_page
|
@@ -226,7 +226,7 @@ class QueryHelper
|
|
226
226
|
@bind_variables[:limit] = limit
|
227
227
|
@bind_variables[:offset] = offset
|
228
228
|
end
|
229
|
-
end
|
229
|
+
end
|
230
230
|
|
231
231
|
def paginated_results
|
232
232
|
{ pagination: pagination_results(),
|
@@ -273,16 +273,16 @@ class QueryHelper
|
|
273
273
|
def search_filter(column_maps)
|
274
274
|
raise ArgumentError.new("search_fields not defined") unless @search_fields.length > 0
|
275
275
|
placement = :where
|
276
|
-
maps = column_maps.select do |cm|
|
276
|
+
maps = column_maps.select do |cm|
|
277
277
|
placement = :having if cm.aggregate
|
278
278
|
@search_fields.include? cm.alias_name
|
279
|
-
end
|
279
|
+
end
|
280
280
|
bind_variable = ('a'..'z').to_a.shuffle[0,20].join.to_sym
|
281
281
|
@bind_variables[bind_variable] = "%#{@search_string}%"
|
282
|
-
filter = "#{maps.map{|m| "#{m.sql_expression}::varchar"}.join(" || ")} ilike :#{bind_variable}"
|
282
|
+
filter = "#{maps.map{|m| "coalesce(#{m.sql_expression}::varchar, '')"}.join(" || ")} ilike :#{bind_variable}"
|
283
283
|
return {
|
284
284
|
filter: filter,
|
285
285
|
placement: placement
|
286
286
|
}
|
287
|
-
end
|
287
|
+
end
|
288
288
|
end
|
@@ -13,7 +13,7 @@ class QueryHelper
|
|
13
13
|
|
14
14
|
model.attribute_names.each do |attribute|
|
15
15
|
if maps.select{|x| x.alias_name == attribute}.empty?
|
16
|
-
maps << ColumnMap.new(alias_name: attribute, sql_expression: "#{model.
|
16
|
+
maps << ColumnMap.new(alias_name: attribute, sql_expression: "#{model.table_name.pluralize}.#{attribute}")
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
data/lib/query_helper/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: query_helper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.19
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Evan McDaniel
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-01-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -199,7 +199,7 @@ homepage: https://github.com/iserve-products/query_helper
|
|
199
199
|
licenses:
|
200
200
|
- MIT
|
201
201
|
metadata: {}
|
202
|
-
post_install_message:
|
202
|
+
post_install_message:
|
203
203
|
rdoc_options: []
|
204
204
|
require_paths:
|
205
205
|
- lib
|
@@ -215,7 +215,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
215
215
|
version: '0'
|
216
216
|
requirements: []
|
217
217
|
rubygems_version: 3.0.3
|
218
|
-
signing_key:
|
218
|
+
signing_key:
|
219
219
|
specification_version: 4
|
220
220
|
summary: Ruby Gem to help with pagination and data formatting at Pattern, Inc.
|
221
221
|
test_files: []
|