query_helper 0.3.8 → 0.4.0

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: 8de4575667fa298b34568c0635c91d7bc056e8f69b17e7c2053a29a974dff831
4
- data.tar.gz: 12b8586b7bd0b14323ea85511dede752fd03d8b0ad12d3704e905fe2f0f8fe56
3
+ metadata.gz: 4ad56f0d478e804e375bb1e51305dad25b306d34a0db834b5ff3f67bfc4aeab1
4
+ data.tar.gz: 401fd61c7e653858ce46527efa430d3ce39ad2ec81b96b245d5870bbc32eac3f
5
5
  SHA512:
6
- metadata.gz: bf2ec789f7bc275fffde36f677711423279cf4746e6cdcd8c14f18d47b5c53053ec7772652b9ea23885dde9b0f63397fcab115624ceac486e004ba12edbcf16e
7
- data.tar.gz: 853857f9e9937833b3199064964a54a20e2a089d786d50e5bc3775543d394e040e45b6c1fdc6ebc589f3febef515ccb1da850ac10115fe97a70bd268447ee4d0
6
+ metadata.gz: f8bad72d56d042dde48a2316682adb871aeba56f19e1518c4488ad0bc12b205e8157542ee1d25fe76bd9c6df27a3f2a1a1e44449f248b2d4891f6d0017899d90
7
+ data.tar.gz: de8c9f4e1f22bc806c9857dfba844350c3ec65ff62bc7be19ad21aa1f53d2204285b1fe571289e54866850f88b68dc1615e8b2708bd8e113a14985162f948921
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- query_helper (0.3.8)
4
+ query_helper (0.4.0)
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 (2.1.0)
92
+ sqlite3 (1.6.4)
93
93
  mini_portile2 (~> 2.8.0)
94
94
  thor (1.1.0)
95
95
  tzinfo (2.0.4)
@@ -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.downcase == comparate_alias.downcase }
20
+ map = @column_maps.find { |m| m.alias_name == comparate_alias }
21
21
  raise InvalidQueryError.new("cannot filter by #{comparate_alias}") unless map
22
22
 
23
23
  # create the filter
@@ -18,7 +18,9 @@ class QueryHelper
18
18
 
19
19
  def remove_comments
20
20
  # Remove SQL inline comments (/* */) and line comments (--)
21
- @sql = @sql.gsub(/\/\*(.*?)\*\//, '').gsub(/--(.*)$/, '')
21
+ @sql = @sql.gsub(%r{/\*[^/]*?\*/}m, '') # Removes multi-line comments (/* ... */)
22
+ .gsub(/--[^\n]*/, '') # Removes single-line comments (--)
23
+
22
24
  @sql.squish!
23
25
  end
24
26
 
@@ -186,7 +188,7 @@ class QueryHelper
186
188
  ColumnMap.new(
187
189
  alias_name: sql_alias,
188
190
  sql_expression: sql_expression.squish,
189
- aggregate: /(array_agg|avg|bit_and|bit_or|bool_and|bool_or|boolor_agg|booland_agg|count|every|json_agg|jsonb_agg|json_object_agg|jsonb_object_agg|max|min|string_agg|sum|xmlagg)\((.*)\)/.match?(sql_expression)
191
+ aggregate: /\b(array_agg|avg|bit_and|bit_or|bool_and|bool_or|boolor_agg|booland_agg|count|every|json_agg|jsonb_agg|json_object_agg|jsonb_object_agg|max|min|string_agg|sum|xmlagg)\((.*)\)/.match?(sql_expression)
190
192
  ) if sql_alias
191
193
  end
192
194
  column_maps.compact
@@ -34,9 +34,7 @@ class QueryHelper
34
34
  direction = sort.split(":")[1]
35
35
  modifier = sort.split(":")[2]
36
36
  begin
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
+ sql_expression = @column_maps.find{ |m| m.alias_name.casecmp?(sort_alias) }.sql_expression
40
38
  rescue NoMethodError => e
41
39
  raise InvalidQueryError.new("Sorting not allowed on column '#{sort_alias}'")
42
40
  end
@@ -1,3 +1,3 @@
1
1
  class QueryHelper
2
- VERSION = "0.3.8"
2
+ VERSION = "0.4.0"
3
3
  end
data/lib/query_helper.rb CHANGED
@@ -10,7 +10,6 @@ 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"
14
13
 
15
14
  class QueryHelper
16
15
 
@@ -281,8 +280,12 @@ class QueryHelper
281
280
  raise ArgumentError.new("search_fields not defined") unless @search_fields.length > 0
282
281
  placement = :where
283
282
  maps = column_maps.select do |cm|
284
- placement = :having if cm.aggregate
285
- @search_fields.map(&:downcase).include? cm.alias_name.downcase
283
+ if @search_fields.include? cm.alias_name
284
+ placement = :having if cm.aggregate
285
+ true
286
+ else
287
+ false
288
+ end
286
289
  end
287
290
  bind_variable = ('a'..'z').to_a.shuffle[0,20].join.to_sym
288
291
  @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.8
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Patterninc
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-09-27 00:00:00.000000000 Z
11
+ date: 2024-11-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -190,7 +190,6 @@ 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
194
193
  - lib/query_helper/query_helper_concern.rb
195
194
  - lib/query_helper/sql_filter.rb
196
195
  - lib/query_helper/sql_manipulator.rb
@@ -217,7 +216,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
217
216
  - !ruby/object:Gem::Version
218
217
  version: '0'
219
218
  requirements: []
220
- rubygems_version: 3.5.16
219
+ rubygems_version: 3.5.22
221
220
  signing_key:
222
221
  specification_version: 4
223
222
  summary: Ruby Gem to help with pagination and data formatting at Pattern, Inc.
@@ -1,18 +0,0 @@
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