Sha256: 7c20850a09281969bd084354613a5f2a26622e2ed0edf210d27b9eb4bf6fc138

Contents?: true

Size: 763 Bytes

Versions: 4

Compression:

Stored size: 763 Bytes

Contents

module InfluxDB
  module Rails
    module Sql
      class Normalizer # :nodoc:
        def initialize(query)
          @query = query.dup
        end

        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

        private

        attr_reader :query
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
influxdb-rails-1.0.3 lib/influxdb/rails/sql/normalizer.rb
influxdb-rails-1.0.2 lib/influxdb/rails/sql/normalizer.rb
influxdb-rails-1.0.1 lib/influxdb/rails/sql/normalizer.rb
influxdb-rails-1.0.1.beta3 lib/influxdb/rails/sql/normalizer.rb