Class: Pgtk::Pool::Txn
- Inherits:
-
Object
- Object
- Pgtk::Pool::Txn
- Defined in:
- lib/pgtk/pool.rb
Overview
A temporary class to execute a single SQL request.
Instance Method Summary collapse
- #exec(query, args = [], result = 0) ⇒ Object
-
#initialize(conn, log) ⇒ Txn
constructor
A new instance of Txn.
Constructor Details
#initialize(conn, log) ⇒ Txn
Returns a new instance of Txn.
157 158 159 160 |
# File 'lib/pgtk/pool.rb', line 157 def initialize(conn, log) @conn = conn @log = log end |
Instance Method Details
#exec(query, args = [], result = 0) ⇒ Object
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
# File 'lib/pgtk/pool.rb', line 162 def exec(query, args = [], result = 0) start = Time.now sql = query.is_a?(Array) ? query.join(' ') : query out = @conn.exec_params(sql, args, result) do |res| if block_given? yield res else rows = [] res.each { |r| rows << r } rows end end @log.debug("#{sql}: #{(start - Time.now).round}ms") out end |