Class: Hyphy::ActiveRecordAdapter

Inherits:
AbstractORMAdapter show all
Defined in:
lib/hyphy/orm_adapters/activerecord_adapter.rb

Class Method Summary collapse

Class Method Details

.subscribe_to_sql_notifications(callback) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/hyphy/orm_adapters/activerecord_adapter.rb', line 7

def self.subscribe_to_sql_notifications(callback)
  ActiveSupport::Notifications.subscribe('sql.active_record') do |*args|
    sql = args[4][:sql]
    binds = args[4][:binds]
    start_time = args[1]
    end_time = args[2]

    sql_statement = callback.call(sql, start_time, end_time)
    sql_statement.binds = binds
  end
end

.time_statement(sql_statement) ⇒ Object



23
24
25
26
27
28
29
30
31
# File 'lib/hyphy/orm_adapters/activerecord_adapter.rb', line 23

def self.time_statement(sql_statement)
  ActiveRecord::Base.connection.clear_query_cache

  binds = sql_statement.binds
  Benchmark.realtime { ActiveRecord::Base.connection.send(:exec_query,
                                                          sql_statement.statement,
                                                          'SQL',
                                                          binds) }
end

.unsubscribe_to_sql_notifications(subscriber) ⇒ Object



19
20
21
# File 'lib/hyphy/orm_adapters/activerecord_adapter.rb', line 19

def self.unsubscribe_to_sql_notifications(subscriber)
  ActiveSupport::Notifications.unsubscribe(subscriber)
end