boss_db_adapter_pgsql:transaction/2 does not pass the database connection to the function it receives

49 views
Skip to first unread message

Juan Jose Comellas

unread,
May 29, 2012, 10:11:38 PM5/29/12
to chica...@googlegroups.com
It looks like the 'pgsql' boss_db adapter (boss_db_adapter_pgsql.erl) is not passing the database connection to the function it receives as argument. This is the current code for the function:

    transaction(Conn, TransactionFun) ->
        case pgsql:with_transaction(Conn, fun(_C) -> TransactionFun() end) of
            {rollback, Reason} -> {aborted, Reason};
            Other -> {atomic, Other}
        end.

Is there a reason why the connection is not being passed?

BTW, has anyone used boss_db independently of the chicagoboss project? If so, how did you automate the model compilation with rebar?

Thanks,


Juanjo

Evan Miller

unread,
May 29, 2012, 11:37:28 PM5/29/12
to chica...@googlegroups.com
Hi Juanjo,

The connection is cached in the process dictionary which is checked
any time you make a call to boss_db, see here:

https://github.com/evanmiller/boss_db/blob/master/src/boss_db.erl#L60
https://github.com/evanmiller/boss_db/blob/master/src/boss_db.erl#L207

It's not passed to the transaction function because the boss_db API
does not take a connection as an argument (the connection management
is all behind-the-scenes).

Of course if you've hit a bug in the PG adapter that would be useful to know :)

Evan
--
Evan Miller
http://www.evanmiller.org/

Juan Jose Comellas

unread,
May 30, 2012, 12:43:44 PM5/30/12
to chica...@googlegroups.com, Evan Miller
I've seen that. The problem is how do I execute a raw SQL query from within my code. Do I use boss_db:execute/1? What if I want to execute a query that has arguments? What's the equivalent of pgsql:equery/3?

Evan Miller

unread,
May 30, 2012, 1:10:04 PM5/30/12
to Juan Jose Comellas, chica...@googlegroups.com
Try this

https://github.com/evanmiller/boss_db/commit/f50fd5d0f40b4a0bff8fb63b6512bdf1629dd277

On Wed, May 30, 2012 at 11:43 AM, Juan Jose Comellas

Juan Jose Comellas

unread,
May 30, 2012, 1:13:16 PM5/30/12
to Evan Miller, chica...@googlegroups.com
I'll try it now. Thanks for the quick response!
Reply all
Reply to author
Forward
0 new messages