Skip to content

Commit

Permalink
fix rails 8
Browse files Browse the repository at this point in the history
  • Loading branch information
omohokcoj committed Dec 21, 2024
1 parent 9ccffc8 commit af6f2d6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 14 deletions.
35 changes: 22 additions & 13 deletions lib/motor/queries/postgresql_exec_query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,30 @@ module PostgresqlExecQuery
module_function

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)
if Rails.version.to_f >= 8.0
result = conn.send(:internal_execute, *statement)
process_result(conn, result)
else
conn.send(:execute_and_clear, *statement) do |result|
process_result(conn, result)
end
end
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
def process_result(conn, 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
Expand Down
2 changes: 1 addition & 1 deletion lib/motor/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module Motor
VERSION = '0.4.32'
VERSION = '0.4.33'
end

0 comments on commit af6f2d6

Please sign in to comment.