Module: DbDebug::ActiveRecord::ConnectionAdapters::PostgreSQLAdapter

Defined in:
lib/db_debug/active_record.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(klass) ⇒ Object



5
6
7
8
9
# File 'lib/db_debug/active_record.rb', line 5

def self.included(klass)
  klass.class_eval do
    alias_method_chain :exec_query, :db_debug
  end
end

Instance Method Details

#exec_query_with_db_debug(sql, name = 'SQL', binds = []) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/db_debug/active_record.rb', line 11

def exec_query_with_db_debug(sql, name = 'SQL', binds = [])
  if DbDebug.enabled            
    DbDebug.count += 1
    start = Time.now
    res = exec_query_without_db_debug(sql, name, binds)
    time = (Time.now - start) * 1000
    
    if DbDebug.verbose
      Logger.log :white, ""
      Logger.log :red, "DB CALL " + "="*72
      Logger.log :green, "SQL:     #{sql.split("\n").join("").strip}"
      Logger.log :green, "BINDS:   #{binds}" if binds.present?
      Logger.log :white, "TIME:    #{time} ms"
      Logger.log :white, caller.delete_if{ |str| str.include?("/gems/") || str.include?("script/rails") }.join("\n")
      Logger.log :red, "="*80
      Logger.log :white, ""
      
    end
    DbDebug.time += time
    res
  else
    exec_query_without_db_debug(sql, name, binds)
  end
end