Sha256: f807ae644c52653c45079d1f878590ffd268fcaf1afe14582c259c137a7fbaef
Contents?: true
Size: 1.17 KB
Versions: 6
Compression:
Stored size: 1.17 KB
Contents
# frozen_string_literal: true module MiniSql module Postgres 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 = PreparedBinds.new end def build(_) raise 'Builder can not be called on prepared connections, instead of `::MINI_SQL.prepared.build(sql).query` use `::MINI_SQL.build(sql).prepared.query`' end def prepared(condition = true) condition ? self : @unprepared end def deserializer_cache @unprepared.deserializer_cache end private def run(sql, params) prepared_sql, binds, _bind_names = @param_binder.bind(sql, *params) prepare_statement_key = @prepared_cache.prepare_statement(prepared_sql) raw_connection.exec_prepared(prepare_statement_key, binds) end end end end
Version data entries
6 entries across 6 versions & 1 rubygems