Module: Refile::Postgres::SmartTransaction

Included in:
Backend, Backend::Reader
Defined in:
lib/refile/postgres/smart_transaction.rb

Constant Summary collapse

PQTRANS_INTRANS =

(idle, within transaction block)

2

Instance Method Summary collapse

Instance Method Details

#ensure_in_transactionObject



19
20
21
22
23
24
25
26
27
# File 'lib/refile/postgres/smart_transaction.rb', line 19

def ensure_in_transaction
  if connection.transaction_status == PQTRANS_INTRANS
    yield
  else
    connection.transaction do
      yield
    end
  end
end

#smart_transactionObject



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/refile/postgres/smart_transaction.rb', line 7

def smart_transaction
  result = nil
  ensure_in_transaction do
    begin
      handle = connection.lo_open(oid)
      result = yield handle
      connection.lo_close(handle)
    end
  end
  result
end