Skip to content

Commit

Permalink
refactor PreparedConnection for more useful ActiveRecord
Browse files Browse the repository at this point in the history
  • Loading branch information
ermolaev committed Aug 22, 2024
1 parent 7fc32ce commit 49dc09b
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions lib/mini_sql/postgres/prepared_connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,10 @@ class PreparedConnection < Connection
attr_reader :unprepared

def initialize(unprepared_connection)
@unprepared = unprepared_connection
@raw_connection = unprepared_connection.raw_connection
@type_map = unprepared_connection.type_map
@param_encoder = unprepared_connection.param_encoder

@prepared_cache = PreparedCache.new(@raw_connection)
@param_binder = unprepared.array_encoder ? PreparedBindsAutoArray.new(unprepared.array_encoder) : PreparedBinds.new
@unprepared = unprepared_connection
@type_map = unprepared_connection.type_map
@param_encoder = unprepared_connection.param_encoder
@param_binder = unprepared.array_encoder ? PreparedBindsAutoArray.new(unprepared.array_encoder) : PreparedBinds.new
end

def build(_)
Expand All @@ -30,8 +27,11 @@ def deserializer_cache

private def run(sql, params)
prepared_sql, binds, _bind_names = @param_binder.bind(sql, *params)

@prepared_cache ||= PreparedCache.new(unprepared.raw_connection)
prepare_statement_key = @prepared_cache.prepare_statement(prepared_sql)
raw_connection.exec_prepared(prepare_statement_key, binds)

unprepared.raw_connection.exec_prepared(prepare_statement_key, binds)
end

end
Expand Down

0 comments on commit 49dc09b

Please sign in to comment.