Sha256: 92ff68e20739fbd64a434ab17dd8261f75ebc8ede4e5e63d99661d3eac2f4c1f
Contents?: true
Size: 843 Bytes
Versions: 9
Compression:
Stored size: 843 Bytes
Contents
# frozen_string_literal: true require 'elastic_apm/util/lru_cache' module ElasticAPM # @api private class SqlSummarizer DEFAULT = 'SQL' TABLE_REGEX = %{["'`]?([A-Za-z0-9_]+)} REGEXES = { /^BEGIN/i => 'BEGIN', /^COMMIT/i => 'COMMIT', /^SELECT .* FROM #{TABLE_REGEX}/i => 'SELECT FROM ', /^INSERT INTO #{TABLE_REGEX}/i => 'INSERT INTO ', /^UPDATE #{TABLE_REGEX}/i => 'UPDATE ', /^DELETE FROM #{TABLE_REGEX}/i => 'DELETE FROM ' }.freeze FORMAT = '%s%s' 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] && match[1].gsub(/["']/, '')) end end || DEFAULT end end end
Version data entries
9 entries across 9 versions & 1 rubygems