Skip to content

Commit

Permalink
Merge pull request #57 from patterninc/PRED-4997_Patch-Query-Helper
Browse files Browse the repository at this point in the history
Pred 4997 patch query helper
  • Loading branch information
ahujaak authored Nov 6, 2024
2 parents f865796 + 17d1ac8 commit 1c1e17b
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
query_helper (0.3.9)
query_helper (0.4.0)
activerecord (> 5)
activesupport (> 5)
sqlite3
Expand Down
6 changes: 4 additions & 2 deletions lib/query_helper/sql_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ def update(sql)

def remove_comments
# Remove SQL inline comments (/* */) and line comments (--)
@sql = @sql.gsub(/\/\*(.*?)\*\//, '').gsub(/--(.*)$/, '')
@sql = @sql.gsub(%r{/\*[^/]*?\*/}m, '') # Removes multi-line comments (/* ... */)
.gsub(/--[^\n]*/, '') # Removes single-line comments (--)

@sql.squish!
end

Expand Down Expand Up @@ -186,7 +188,7 @@ def find_aliases
ColumnMap.new(
alias_name: sql_alias,
sql_expression: sql_expression.squish,
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)
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)
) if sql_alias
end
column_maps.compact
Expand Down
2 changes: 1 addition & 1 deletion lib/query_helper/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
class QueryHelper
VERSION = "0.3.9"
VERSION = "0.4.0"
end
2 changes: 2 additions & 0 deletions spec/fixtures/controllers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
class ApplicationController < ActionController::API
include Rails.application.routes.url_helpers
include QueryHelper::QueryHelperConcern
include ActionController::RequestForgeryProtection
before_action :create_query_helper
protect_from_forgery with: :exception
end

class ParentsController < ApplicationController
Expand Down

0 comments on commit 1c1e17b

Please sign in to comment.