Skip to content

Commit

Permalink
Merge pull request #173 from inaka/jfacorro.170.remove_single_connection
Browse files Browse the repository at this point in the history
[Closes #170] Return new connection per call to sumo_backend_pgsql:get_connection
  • Loading branch information
igaray committed Jun 25, 2015
2 parents fcccd3e + 0ce737b commit bf05bb0
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/sumo_backend_pgsql.erl
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,15 @@ init(Options) ->
Opts = [{port, proplists:get_value(port, Options, 5432)},
{database, proplists:get_value(database, Options)}],

{ok, Conn} = pgsql:connect(Host, Username, Password, Opts),

{ok, #{conn => Conn}}.
{ok, #{host => Host, user => Username, pass => Password, opts => Opts}}.

-spec handle_call(term(), term(), state()) -> {reply, term(), state()}.
handle_call(get_connection, _From, State = #{conn := Conn}) ->
handle_call(get_connection, _From, State) ->
#{ host := Host
, user := Username
, pass := Password
, opts := Opts} = State,
{ok, Conn} = pgsql:connect(Host, Username, Password, Opts),
{reply, Conn, State}.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Expand Down

0 comments on commit bf05bb0

Please sign in to comment.