Module: SQLRewriter::Adapters::ActiveRecord::Decorator
- Includes:
- Hooks::AfterQuery, Hooks::BeforeQuery
- Defined in:
- lib/sql-rewriter/adapters.rb
Class Method Summary collapse
Instance Method Summary collapse
- #exec_query_with_sqlr(sql, name = 'SQL', binds = []) ⇒ Object
- #execute_with_sqlr(sql, name = nil, binds) ⇒ Object
Methods included from Hooks::BeforeQuery
Methods included from Hooks::AfterQuery
Class Method Details
.included(decorated_class) ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/sql-rewriter/adapters.rb', line 69 def self.included(decorated_class) decorated_class.class_eval do if decorated_class.method_defined?(:execute) alias_method :execute_without_sqlr, :execute alias_method :execute, :execute_with_sqlr end is_mysql2 = defined?(ActiveRecord::ConnectionAdapters::Mysql2Adapter) && ActiveRecord::ConnectionAdapters::Mysql2Adapter == decorated_class # Dont instrument exec_query on mysql2 and AR 3.2+, as it calls execute internally unless is_mysql2 && ActiveRecord::VERSION::STRING > "3.1" if decorated_class.method_defined?(:exec_query) alias_method :exec_query_without_sqlr, :exec_query alias_method :exec_query, :exec_query_with_sqlr end end end end |
Instance Method Details
#exec_query_with_sqlr(sql, name = 'SQL', binds = []) ⇒ Object
95 96 97 |
# File 'lib/sql-rewriter/adapters.rb', line 95 def exec_query_with_sqlr(sql, name = 'SQL', binds = []) after_query(exec_query_without_sqlr(before_query(sql, binds), name, binds)) end |
#execute_with_sqlr(sql, name = nil, binds) ⇒ Object
90 91 92 93 |
# File 'lib/sql-rewriter/adapters.rb', line 90 def execute_with_sqlr(sql, name = nil, binds) after_query(execute_without_sqlr(before_query(sql, binds), name)) end |