Skip to content

tholschuh/epgsql_connpool

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

Pool application for epgsql

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Erlang 100.0%