Skip to content

Commit af6f2d6

Browse files
committed
fix rails 8
1 parent 9ccffc8 commit af6f2d6

File tree

2 files changed

+23
-14
lines changed

2 files changed

+23
-14
lines changed

lib/motor/queries/postgresql_exec_query.rb

+22-13
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,30 @@ module PostgresqlExecQuery
66
module_function
77

88
def call(conn, statement)
9-
conn.send(:execute_and_clear, *statement) do |result|
10-
types = {}
11-
fields = result.fields
12-
13-
fields.each_with_index do |fname, i|
14-
ftype = result.ftype i
15-
fmod = result.fmod i
16-
types[fname] = conn.send(:get_oid_type, ftype, fmod, fname)
9+
if Rails.version.to_f >= 8.0
10+
result = conn.send(:internal_execute, *statement)
11+
process_result(conn, result)
12+
else
13+
conn.send(:execute_and_clear, *statement) do |result|
14+
process_result(conn, result)
1715
end
16+
end
17+
end
1818

19-
if conn.respond_to?(:build_result, true)
20-
conn.send(:build_result, columns: fields, rows: result.values, column_types: types)
21-
else
22-
ActiveRecord::Result.new(fields, result.values, types)
23-
end
19+
def process_result(conn, result)
20+
types = {}
21+
fields = result.fields
22+
23+
fields.each_with_index do |fname, i|
24+
ftype = result.ftype i
25+
fmod = result.fmod i
26+
types[fname] = conn.send(:get_oid_type, ftype, fmod, fname)
27+
end
28+
29+
if conn.respond_to?(:build_result, true)
30+
conn.send(:build_result, columns: fields, rows: result.values, column_types: types)
31+
else
32+
ActiveRecord::Result.new(fields, result.values, types)
2433
end
2534
end
2635
end

lib/motor/version.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# frozen_string_literal: true
22

33
module Motor
4-
VERSION = '0.4.32'
4+
VERSION = '0.4.33'
55
end

0 commit comments

Comments
 (0)