module ServiceTemplate::ActiveRecordStats

Constants

SQL_INSERT_DELETE_PARSER_REGEXP
SQL_SELECT_REGEXP
SQL_UPDATE_REGEXP

Public Class Methods

extract_from_sql_inserts_deletes(query) click to toggle source

Returns the table and query type

# File lib/service_template/active_record_extensions/stats.rb, line 9
def self.extract_from_sql_inserts_deletes(query)
  m = query.match(SQL_INSERT_DELETE_PARSER_REGEXP)
  [m[:table], m[:action]]
end
extract_sql_content(query) click to toggle source
# File lib/service_template/active_record_extensions/stats.rb, line 24
def self.extract_sql_content(query)
  table = action = nil
  if query.match(SQL_UPDATE_REGEXP)
    table, action = extract_sql_updates(query)
  elsif query.match(SQL_SELECT_REGEXP)
    table, action =  extract_sql_selects(query)
  elsif query.match(SQL_INSERT_DELETE_PARSER_REGEXP)
    table, action =  extract_from_sql_inserts_deletes(query)
  end
  [table, action]
end
extract_sql_selects(query) click to toggle source
# File lib/service_template/active_record_extensions/stats.rb, line 14
def self.extract_sql_selects(query)
  m = query.match(SQL_SELECT_REGEXP)
  [m[:table], 'SELECT']
end
extract_sql_updates(query) click to toggle source
# File lib/service_template/active_record_extensions/stats.rb, line 19
def self.extract_sql_updates(query)
  m = query.match(SQL_UPDATE_REGEXP)
  [m[:table], 'UPDATE']
end