The README file contains this example:
pgapp:with_transaction(fun() ->
pgapp:squery("update ..."),
pgapp:squery("delete from ..."),
pgapp:equery("select ? from ?", ["*", Table])
end).
The problem in this approach is that "BEGIN" and "COMMIT" actually happens in one connection, but all the queries inside happens in another.
Look at the following code of pgapp_worker.erl:
equery(PoolName, Sql, Params, Timeout) ->
middle_man_transaction(PoolName,
fun (W) ->
gen_server:call(W, {equery, Sql, Params},
Timeout)
end, Timeout).
...
with_transaction(PoolName, Fun, Timeout) ->
middle_man_transaction(PoolName,
fun (W) ->
gen_server:call(W, {transaction, Fun},
Timeout)
end, Timeout).
middle_man_transaction() will dedicate a separate poolboy worker for each query, including a transaction itself. So when with_transaction() is called, it gets a poolboy worker and runs "BEGIN" in it (inside epsql.erl). Thus the worker is busy waiting for the queries to be executed. But the queries run as separate calls to poolboy which means they get different workers.
The README file contains this example:
The problem in this approach is that "BEGIN" and "COMMIT" actually happens in one connection, but all the queries inside happens in another.
Look at the following code of pgapp_worker.erl:
middle_man_transaction()will dedicate a separate poolboy worker for each query, including a transaction itself. So whenwith_transaction()is called, it gets a poolboy worker and runs "BEGIN" in it (inside epsql.erl). Thus the worker is busy waiting for the queries to be executed. But the queries run as separate calls to poolboy which means they get different workers.