query_helper 0.3.5 → 0.3.8
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/.github/workflows/brakeman.yml +1 -1
- data/Gemfile.lock +2 -2
- data/lib/query_helper/invalid_sort_param_error.rb +18 -0
- data/lib/query_helper/sql_filter.rb +1 -1
- data/lib/query_helper/sql_sort.rb +7 -4
- data/lib/query_helper/version.rb +1 -1
- data/lib/query_helper.rb +2 -1
- metadata +7 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8de4575667fa298b34568c0635c91d7bc056e8f69b17e7c2053a29a974dff831
|
4
|
+
data.tar.gz: 12b8586b7bd0b14323ea85511dede752fd03d8b0ad12d3704e905fe2f0f8fe56
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bf2ec789f7bc275fffde36f677711423279cf4746e6cdcd8c14f18d47b5c53053ec7772652b9ea23885dde9b0f63397fcab115624ceac486e004ba12edbcf16e
|
7
|
+
data.tar.gz: 853857f9e9937833b3199064964a54a20e2a089d786d50e5bc3775543d394e040e45b6c1fdc6ebc589f3febef515ccb1da850ac10115fe97a70bd268447ee4d0
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
query_helper (0.3.
|
4
|
+
query_helper (0.3.8)
|
5
5
|
activerecord (> 5)
|
6
6
|
activesupport (> 5)
|
7
7
|
sqlite3
|
@@ -89,7 +89,7 @@ GEM
|
|
89
89
|
rspec-mocks (~> 3.10)
|
90
90
|
rspec-support (~> 3.10)
|
91
91
|
rspec-support (3.10.2)
|
92
|
-
sqlite3 (1.
|
92
|
+
sqlite3 (2.1.0)
|
93
93
|
mini_portile2 (~> 2.8.0)
|
94
94
|
thor (1.1.0)
|
95
95
|
tzinfo (2.0.4)
|
@@ -0,0 +1,18 @@
|
|
1
|
+
class QueryHelper
|
2
|
+
class InvalidSortParamError < StandardError
|
3
|
+
|
4
|
+
attr_reader :sort_string
|
5
|
+
|
6
|
+
def initialize(msg='Invalid sort param', sort_string='')
|
7
|
+
@sort_string = sort_string
|
8
|
+
super(msg)
|
9
|
+
end
|
10
|
+
|
11
|
+
def as_json
|
12
|
+
{
|
13
|
+
'error' => message,
|
14
|
+
'sort_param' => sort_string
|
15
|
+
}
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -17,7 +17,7 @@ class QueryHelper
|
|
17
17
|
|
18
18
|
@filter_values.each do |comparate_alias, criteria|
|
19
19
|
# Find the sql mapping if it exists
|
20
|
-
map = @column_maps.find { |m| m.alias_name == comparate_alias }
|
20
|
+
map = @column_maps.find { |m| m.alias_name.downcase == comparate_alias.downcase }
|
21
21
|
raise InvalidQueryError.new("cannot filter by #{comparate_alias}") unless map
|
22
22
|
|
23
23
|
# create the filter
|
@@ -5,12 +5,13 @@ class QueryHelper
|
|
5
5
|
|
6
6
|
attr_accessor :column_maps, :select_strings, :sort_tiebreak, :column_sort_order
|
7
7
|
|
8
|
-
def initialize(sort_string: "", sort_tiebreak: "", column_maps: [], column_sort_order: {})
|
8
|
+
def initialize(sort_string: "", sort_tiebreak: "", column_maps: [], column_sort_order: {}, keep_nulls_last: false)
|
9
9
|
@sort_string = sort_string
|
10
10
|
@column_maps = column_maps
|
11
11
|
@sort_tiebreak = sort_tiebreak
|
12
12
|
@column_sort_order = column_sort_order
|
13
13
|
@select_strings = []
|
14
|
+
@keep_nulls_last = keep_nulls_last
|
14
15
|
end
|
15
16
|
|
16
17
|
def parse_sort_string
|
@@ -33,7 +34,9 @@ class QueryHelper
|
|
33
34
|
direction = sort.split(":")[1]
|
34
35
|
modifier = sort.split(":")[2]
|
35
36
|
begin
|
36
|
-
|
37
|
+
sort_col = @column_maps.find{ |m| m.alias_name.casecmp?(sort_alias) }
|
38
|
+
raise InvalidSortParamError.new("Invalid sort param", sort_alias) if sort_col.nil?
|
39
|
+
sql_expression = sort_col.sql_expression
|
37
40
|
rescue NoMethodError => e
|
38
41
|
raise InvalidQueryError.new("Sorting not allowed on column '#{sort_alias}'")
|
39
42
|
end
|
@@ -41,12 +44,12 @@ class QueryHelper
|
|
41
44
|
if direction == "desc"
|
42
45
|
case ActiveRecord::Base.connection.adapter_name
|
43
46
|
when "SQLite" # SQLite is used in the test suite
|
44
|
-
direction = "desc"
|
47
|
+
direction = @keep_nulls_last ? "desc nulls last" : "desc"
|
45
48
|
else
|
46
49
|
direction = "desc nulls last"
|
47
50
|
end
|
48
51
|
else
|
49
|
-
direction = "asc"
|
52
|
+
direction = @keep_nulls_last ? "asc nulls last" : "asc"
|
50
53
|
end
|
51
54
|
|
52
55
|
case modifier
|
data/lib/query_helper/version.rb
CHANGED
data/lib/query_helper.rb
CHANGED
@@ -10,6 +10,7 @@ require "query_helper/sql_manipulator"
|
|
10
10
|
require "query_helper/sql_filter"
|
11
11
|
require "query_helper/sql_sort"
|
12
12
|
require "query_helper/invalid_query_error"
|
13
|
+
require "query_helper/invalid_sort_param_error"
|
13
14
|
|
14
15
|
class QueryHelper
|
15
16
|
|
@@ -281,7 +282,7 @@ class QueryHelper
|
|
281
282
|
placement = :where
|
282
283
|
maps = column_maps.select do |cm|
|
283
284
|
placement = :having if cm.aggregate
|
284
|
-
@search_fields.include? cm.alias_name
|
285
|
+
@search_fields.map(&:downcase).include? cm.alias_name.downcase
|
285
286
|
end
|
286
287
|
bind_variable = ('a'..'z').to_a.shuffle[0,20].join.to_sym
|
287
288
|
@bind_variables[bind_variable] = "%#{@search_string}%"
|
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.3.
|
4
|
+
version: 0.3.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Patterninc
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-09-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -190,6 +190,7 @@ files:
|
|
190
190
|
- lib/query_helper/column_map.rb
|
191
191
|
- lib/query_helper/filter.rb
|
192
192
|
- lib/query_helper/invalid_query_error.rb
|
193
|
+
- lib/query_helper/invalid_sort_param_error.rb
|
193
194
|
- lib/query_helper/query_helper_concern.rb
|
194
195
|
- lib/query_helper/sql_filter.rb
|
195
196
|
- lib/query_helper/sql_manipulator.rb
|
@@ -201,7 +202,7 @@ homepage: https://github.com/patterninc/query_helper
|
|
201
202
|
licenses:
|
202
203
|
- MIT
|
203
204
|
metadata: {}
|
204
|
-
post_install_message:
|
205
|
+
post_install_message:
|
205
206
|
rdoc_options: []
|
206
207
|
require_paths:
|
207
208
|
- lib
|
@@ -216,8 +217,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
216
217
|
- !ruby/object:Gem::Version
|
217
218
|
version: '0'
|
218
219
|
requirements: []
|
219
|
-
rubygems_version: 3.
|
220
|
-
signing_key:
|
220
|
+
rubygems_version: 3.5.16
|
221
|
+
signing_key:
|
221
222
|
specification_version: 4
|
222
223
|
summary: Ruby Gem to help with pagination and data formatting at Pattern, Inc.
|
223
224
|
test_files: []
|