Module: Immunio::QueryExecutionHooks

Extended by:
ActiveSupport::Concern
Defined in:
lib/immunio/plugins/active_record.rb

Overview

Hook into the SQL query execution methods of Rails. Since all executed queries inside Rails are logged, we hook into the ‘log` method to catch them all.

Instance Method Summary collapse

Instance Method Details

#log_with_immunio(sql, name = "SQL", binds = [], *args) ⇒ Object



722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
# File 'lib/immunio/plugins/active_record.rb', line 722

def log_with_immunio(sql, name = "SQL", binds = [], *args)
  # Some rails tests (in particular postresql) call :log with nil `sql`.
  if sql && Request.current
    QueryTracker.instance.call(
      {
        sql: sql,
        connection_id: object_id,
        binds: binds
      },
      adapter_name)
  end

  # Log and execute the query
  log_without_immunio(sql, name, binds, *args) { yield }
end