Method: PG::EM::ConnectionPool#transaction

Defined in:
lib/pg/em/connection_pool.rb

#transaction(&blk) ⇒ Object

Executes a BEGIN at the start of the block and a COMMIT at the end of the block or ROLLBACK if any exception occurs. Calls to transaction may be nested, however without sub-transactions (save points).

Examples:

Transactions

pg = PG::EM::ConnectionPool.new size: 10
pg.transaction do
  pg.exec('insert into animals (family, species) values ($1,$2)',
          [family, species])
  num = pg.query('select count(*) from people where family=$1',
          [family]).get_value(0,0)
  pg.exec('update stats set count = $1 where family=$2',
          [num, family])
end

See Also:



298
299
300
301
302
# File 'lib/pg/em/connection_pool.rb', line 298

def transaction(&blk)
  hold do |pg|
    pg.transaction(&blk)
  end
end