Module: ActiveRecord::ConnectionAdapters::PostgreSQL::DatabaseStatements

Defined in:
lib/active_record_json_explain/activerecord/monkey_patches/json_explain.rb

Instance Method Summary collapse

Instance Method Details

#explain(arel, binds = [], json: false) ⇒ Object



46
47
48
49
50
# File 'lib/active_record_json_explain/activerecord/monkey_patches/json_explain.rb', line 46

def explain(arel, binds = [], json: false) # NOTE: add arg json
  format_option = "(FORMAT JSON)" if json # NOTE: get format option
  sql = "EXPLAIN #{format_option} #{to_sql(arel, binds)}" # NOTE: set format option
  PostgreSQL::ExplainPrettyPrinter.new.pp(exec_query(sql, "EXPLAIN", binds))
end