Class: Atatus::SqlSummarizer Private
- Inherits:
-
Object
- Object
- Atatus::SqlSummarizer
- Defined in:
- lib/atatus/sql_summarizer.rb
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Constant Summary collapse
- DEFAULT =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
'SQL'
- TABLE_REGEX =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
%{["'`]?([A-Za-z0-9_]+)["'`]?}
- REGEXES =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
{ /^BEGIN/iu => 'BEGIN', /^COMMIT/iu => 'COMMIT', /^SELECT .* FROM #{TABLE_REGEX}/iu => 'SELECT FROM ', /^INSERT INTO #{TABLE_REGEX}/iu => 'INSERT INTO ', /^UPDATE #{TABLE_REGEX}/iu => 'UPDATE ', /^DELETE FROM #{TABLE_REGEX}/iu => 'DELETE FROM ' }.freeze
- FORMAT =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
'%s%s'
Class Method Summary collapse
- .cache ⇒ Object private
Instance Method Summary collapse
- #summarize(sql) ⇒ Object private
Class Method Details
.cache ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
39 40 41 |
# File 'lib/atatus/sql_summarizer.rb', line 39 def self.cache @cache ||= Util::LruCache.new end |
Instance Method Details
#summarize(sql) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
43 44 45 46 47 48 49 50 51 |
# File 'lib/atatus/sql_summarizer.rb', line 43 def summarize(sql) sql = sql.encode('utf-8', invalid: :replace, undef: :replace) self.class.cache[sql] ||= REGEXES.find do |regex, sig| if (match = sql[0...1000].match(regex)) break format(FORMAT, sig, match[1] && match[1].gsub(/["']/, '')) end end || DEFAULT end |