Sha256: bbef761565dac7b99162d4a01f4a5d57bfa70c2dd5a5d1aef24e460993b524b1

Contents?: true

Size: 428 Bytes

Versions: 5

Compression:

Stored size: 428 Bytes

Contents

require 'active_record'

class << ActiveRecord::Base.connection
  IGNORED_SQL = [/^PRAGMA/, /^SELECT currval/, /^SELECT CAST/, /^SELECT @@IDENTITY/, /^SELECT @@ROWCOUNT/, /^SHOW FIELDS /]

  def execute_with_counting(sql, name = nil, &block)
    $query_count ||= 0
    $query_count  += 1 unless IGNORED_SQL.any? { |r| sql =~ r }
    execute_without_counting(sql, name, &block)
  end

  alias_method_chain :execute, :counting
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
arid_cache-1.4.4 test/lib/add_query_counting_to_active_record.rb
arid_cache-1.4.3 test/lib/add_query_counting_to_active_record.rb
arid_cache-1.4.2 test/lib/add_query_counting_to_active_record.rb
arid_cache-1.4.1 test/lib/add_query_counting_to_active_record.rb
arid_cache-1.4.0 test/lib/add_query_counting_to_active_record.rb