Class: InfluxDB::Rails::Sql::Normalizer
- Inherits:
-
Object
- Object
- InfluxDB::Rails::Sql::Normalizer
- Defined in:
- lib/influxdb/rails/sql/normalizer.rb
Overview
:nodoc:
Instance Method Summary collapse
-
#initialize(query) ⇒ Normalizer
constructor
A new instance of Normalizer.
- #perform ⇒ Object
Constructor Details
#initialize(query) ⇒ Normalizer
Returns a new instance of Normalizer.
5 6 7 |
# File 'lib/influxdb/rails/sql/normalizer.rb', line 5 def initialize(query) @query = query.dup end |
Instance Method Details
#perform ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/influxdb/rails/sql/normalizer.rb', line 9 def perform 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 |