Module: Motor::Queries::PostgresqlExecQuery

Defined in:
lib/motor/queries/postgresql_exec_query.rb

Class Method Summary collapse

Class Method Details

.call(conn, statement) ⇒ Object


8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/motor/queries/postgresql_exec_query.rb', line 8

def call(conn, statement)
  conn.send(:execute_and_clear, *statement) do |result|
    types = {}
    fields = result.fields

    fields.each_with_index do |fname, i|
      ftype = result.ftype i
      fmod  = result.fmod i
      types[fname] = conn.send(:get_oid_type, ftype, fmod, fname)
    end

    if conn.respond_to?(:build_result, true)
      conn.send(:build_result, columns: fields, rows: result.values, column_types: types)
    else
      ActiveRecord::Result.new(fields, result.values, types)
    end
  end
end