Class: MiniSql::Mysql::PreparedConnection

Inherits:
Connection show all
Defined in:
lib/mini_sql/mysql/prepared_connection.rb

Instance Attribute Summary collapse

Attributes inherited from Connection

#param_encoder, #raw_connection

Instance Method Summary collapse

Methods inherited from Connection

#escape_string, #exec, #query, #query_array, #query_decorator, #query_hash, #query_single

Methods inherited from Connection

#escape_string, #exec, get, #query, #query_decorator, #query_each, #query_each_hash, #query_hash, #query_single, #to_sql

Constructor Details

#initialize(unprepared_connection) ⇒ PreparedConnection

Returns a new instance of PreparedConnection.



9
10
11
12
13
14
15
16
# File 'lib/mini_sql/mysql/prepared_connection.rb', line 9

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

  @prepared_cache     = PreparedCache.new(@raw_connection)
  @param_binder       = PreparedBinds.new
end

Instance Attribute Details

#unpreparedObject (readonly)

Returns the value of attribute unprepared.



7
8
9
# File 'lib/mini_sql/mysql/prepared_connection.rb', line 7

def unprepared
  @unprepared
end

Instance Method Details

#build(_) ⇒ Object



18
19
20
# File 'lib/mini_sql/mysql/prepared_connection.rb', line 18

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

#deserializer_cacheObject



26
27
28
# File 'lib/mini_sql/mysql/prepared_connection.rb', line 26

def deserializer_cache
  @unprepared.deserializer_cache
end

#prepared(condition = true) ⇒ Object



22
23
24
# File 'lib/mini_sql/mysql/prepared_connection.rb', line 22

def prepared(condition = true)
  condition ? self : @unprepared
end