Module: Napa::ActiveRecordStats
- Defined in:
- lib/napa/active_record_extensions/stats.rb
Constant Summary collapse
- SQL_INSERT_DELETE_PARSER_REGEXP =
/^(?<action>\w+)\s(\w+)\s\W*(?<table>\w+)/
- SQL_SELECT_REGEXP =
/select .*? FROM \W*(?<table>\w+)/i
- SQL_UPDATE_REGEXP =
/update \W*(?<table>\w+)/i
Class Method Summary collapse
-
.extract_from_sql_inserts_deletes(query) ⇒ Object
Returns the table and query type.
- .extract_sql_content(query) ⇒ Object
- .extract_sql_selects(query) ⇒ Object
- .extract_sql_updates(query) ⇒ Object
Class Method Details
.extract_from_sql_inserts_deletes(query) ⇒ Object
Returns the table and query type
9 10 11 12 |
# File 'lib/napa/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) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/napa/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) ⇒ Object
14 15 16 17 |
# File 'lib/napa/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) ⇒ Object
19 20 21 22 |
# File 'lib/napa/active_record_extensions/stats.rb', line 19 def self.extract_sql_updates(query) m = query.match(SQL_UPDATE_REGEXP) [m[:table], 'UPDATE'] end |