class ActiveMonitoring::SqlNormalizer

Attributes

query[R]

Public Class Methods

new(query:) click to toggle source
# File lib/active_monitoring/sql_normalizer.rb, line 3
def initialize(query:)
  @query = query
end

Public Instance Methods

to_s() click to toggle source
# File lib/active_monitoring/sql_normalizer.rb, line 7
def to_s
  query.squish!
  query.gsub!(/(\s(=|>|<|>=|<=|<>|!=)\s)('[^']+'|[\$\+\-\w\.]+)/, '\1xxx')
  query.gsub!(/(\sIN\s)\([^\(\)]+\)/i, '\1(xxx)')
  regex = /(\sBETWEEN\s)('[^']+'|[\+\-\w\.]+)(\sAND\s)('[^']+'|[\+\-\w\.]+)/i
  query.gsub!(regex, '\1xxx\3xxx')
  query.gsub!(/(\sVALUES\s)\(.+\)/i, '\1(xxx)')
  query.gsub!(/(\s(LIKE|ILIKE|SIMILAR TO|NOT SIMILAR TO)\s)('[^']+')/i, '\1xxx')
  query.gsub!(/(\s(LIMIT|OFFSET)\s)(\d+)/i, '\1xxx')
  query
end