Sha256: df13df0b9de3bdd44441bc6117937a40dd7e8f3449a033ac46fb6290298b8c88

Contents?: true

Size: 677 Bytes

Versions: 11

Compression:

Stored size: 677 Bytes

Contents

# frozen_string_literal: true

require 'elastic_apm/util/lru_cache'

module ElasticAPM
  # @api private
  class SqlSummarizer
    REGEXES = {
      /^SELECT .* FROM ([^ ]+)/i => 'SELECT FROM ',
      /^INSERT INTO ([^ ]+)/i => 'INSERT INTO ',
      /^UPDATE ([^ ]+)/i => 'UPDATE ',
      /^DELETE FROM ([^ ]+)/i => 'DELETE FROM '
    }.freeze

    FORMAT = '%s%s'.freeze

    def self.cache
      @cache ||= Util::LruCache.new
    end

    def summarize(sql)
      self.class.cache[sql] ||=
        REGEXES.find do |regex, sig|
          if (match = sql.match(regex))
            break format(FORMAT, sig, match[1].gsub(/["']/, ''))
          end
        end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
elastic-apm-0.6.2 lib/elastic_apm/sql_summarizer.rb
elastic-apm-0.6.1 lib/elastic_apm/sql_summarizer.rb
elastic-apm-0.5.1 lib/elastic_apm/sql_summarizer.rb
elastic-apm-0.5.0 lib/elastic_apm/sql_summarizer.rb
elastic-apm-0.4.5 lib/elastic_apm/sql_summarizer.rb
elastic-apm-0.4.4 lib/elastic_apm/sql_summarizer.rb
elastic-apm-0.4.3 lib/elastic_apm/sql_summarizer.rb
elastic-apm-0.4.2 lib/elastic_apm/sql_summarizer.rb
elastic-apm-0.4.1 lib/elastic_apm/sql_summarizer.rb
elastic-apm-0.4.0 lib/elastic_apm/sql_summarizer.rb
elastic-apm-0.3.0 lib/elastic_apm/sql_summarizer.rb