Sha256: 2dbd73cf2c74aa23c7d302b12ba19ad97bb7847b8b2f1916c68f58a67b95b365
Contents?: true
Size: 1.17 KB
Versions: 3
Compression:
Stored size: 1.17 KB
Contents
# frozen_string_literal: true module MiniSql module Sqlite class PreparedConnection < Connection attr_reader :unprepared def initialize(unprepared_connection, deserializer_cache) @unprepared = unprepared_connection @raw_connection = unprepared_connection.raw_connection @deserializer_cache = deserializer_cache @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 private def run(sql, params) prepared_sql, binds, _bind_names = @param_binder.bind(sql, params) statement = @prepared_cache.prepare_statement(prepared_sql) statement.bind_params(binds) if block_given? yield statement.execute else statement.execute.to_a end end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
mini_sql-1.1.2 | lib/mini_sql/sqlite/prepared_connection.rb |
mini_sql-1.1.1 | lib/mini_sql/sqlite/prepared_connection.rb |
mini_sql-1.1.0 | lib/mini_sql/sqlite/prepared_connection.rb |