Last Updated: February 25, 2016
·
1.094K
· cstar

Debugging PostgreSQL queries with erlang and ChicagoBoss

Chicago Boss is a web framework in erlang.

It ships with boss_db, a very capable ORM.
Unfortunately, there is no debug output of the SQL generated.

redbug, tool of the eper erlang performance suite will do that for us.

Add :

{eper, ".*", {git, "git://github.com/massemanet/eper.git",  "HEAD"}

to your webapp's rebar.config

./rebar get-deps compile

Restart Chicago Boss.

Launch redbug to intercept the messages to PostgreSQL :

(fenwick@Boulette)33> redbug:start({pgsql,equery}).
{150,2}
(fenwick@Boulette)34> scenarios_helper:acl_for(U,S).

17:35:32 <{boss_db_controller,init,1}> {pgsql,equery,
        [<0.94.0>,
         ["SELECT * FROM ","acls"," WHERE ",
          ["scenario = 1 AND ",
           "fuser = 1 AND "," TRUE"],
          " ORDER BY ","id"," ","ASC",[]],
         []]}
none
redbug done, timeout - 1  

It obviously works for any function of any module and many more, check out the man page.