Sha256: 31f84dba615072d7567290ac982f9bccab0612a2f6068a77f0a3a3c790ba6454
Contents?: true
Size: 1.37 KB
Versions: 13
Compression:
Stored size: 1.37 KB
Contents
module Rack class Bug class SQLPanel class Query include Rack::Bug::FilteredBacktrace attr_reader :sql attr_reader :time def initialize(sql, time, backtrace = []) @sql = sql @time = time @backtrace = backtrace end def human_time "%.2fms" % (@time * 1_000) end def inspectable? sql.strip =~ /^SELECT /i end def with_profiling self.class.execute("SET PROFILING=1") result = yield self.class.execute("SET PROFILING=0") return result end def explain self.class.execute "EXPLAIN #{@sql}" end def profile with_profiling do execute self.class.execute <<-SQL SELECT * FROM information_schema.profiling WHERE query_id = (SELECT query_id FROM information_schema.profiling ORDER BY query_id DESC LIMIT 1) SQL end end def execute self.class.execute(@sql) end def valid_hash?(secret_key, possible_hash) hash = Digest::SHA1.hexdigest [secret_key, @sql].join(":") possible_hash == hash end def self.execute(sql) ActiveRecord::Base.connection.execute(sql) end end end end end
Version data entries
13 entries across 13 versions & 5 rubygems