Skip to content
Pool application for epgsql
Erlang
Find file
Pull request Compare This branch is 15 commits ahead, 17 commits behind smarkets:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
ebin
src
.gitignore
LICENSE
Makefile
README
rebar
rebar.config

README

Erlang PostgreSQL Database Client Pool for epgsql

Configure application env like so:

    application:start(epgsql),
    application:set_env(epgsql_connpool, pools, 
        [ {maindb, 
                [
                    {host,      "127.0.0.1"}, 
                    {username,  "postgres"}, 
                    {password,  ""}, 
                    {size,      10}, 
                    {opts, [
                            {timeout,  5000}, 
                            {database, "my_database"}
                           ]}
                ]
          }
        ]
    ),
    application:start(epgsql_connpool).

And to make queries:
    
    {atomic, NumRows} = 
    epgsql_connpool:transaction( maindb, fun(Db) ->
        Sql = "SELECT count(*) FROM my_table WHERE id = $1;"
        {ok, _, [{Ret}]} = pgsql:equery(Db, Sql, [123]),
        Ret
    end).

With transaction(), all queries made within the fun are surrounded by a 
BEGIN/COMMIT/ROLLBACK.

With dirty(), the statements are run as-is, not in a transaction.

Something went wrong with that request. Please try again.