Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Deal with epgsql slightly better

git-svn-id: http://dev.brendonh.org/svn/evo/trunk@72 b2fba486-9eff-4e6f-b9e8-fc05d33d65a9
  • Loading branch information...
commit f69fa6f4da56d1375746af052eb2468889f9e963 1 parent 6959bd9
@brendonh authored
Showing with 81 additions and 7 deletions.
  1. +74 −0 evo/src/evoepgsql.erl
  2. +7 −7 evo/src/evosite_sup.erl
View
74 evo/src/evoepgsql.erl
@@ -0,0 +1,74 @@
+%%%-------------------------------------------------------------------
+%%% File : evoepgsql.erl
+%%% Author : Brendon Hogger <brendonh@dev.brendonh.org>
+%%% Description : Serialize epgsql calls
+%%%
+%%% Created : 23 Jul 2009 by Brendon Hogger <brendonh@dev.brendonh.org>
+%%%-------------------------------------------------------------------
+-module(evoepgsql).
+
+-behaviour(gen_server).
+
+-include("evo.hrl").
+
+%% API
+-export([start_link/5, equery/3]).
+
+%% gen_server callbacks
+-export([init/1, handle_call/3, handle_cast/2, handle_info/2,
+ terminate/2, code_change/3]).
+
+-record(state, {
+ conn
+}).
+
+
+
+%%====================================================================
+%% API
+%%====================================================================
+start_link(Name, Host, User, Pass, Opts) ->
+ gen_server:start_link({local, Name}, ?MODULE, [Host, User, Pass, Opts], []).
+
+equery(Self, SQL, Args) ->
+ gen_server:call(Self, {equery, SQL, Args}).
+
+
+
+%%====================================================================
+%% gen_server callbacks
+%%====================================================================
+
+
+init([Host, User, Pass, Opts]) ->
+ {ok, C} = pgsql:connect(Host, [User], [Pass], Opts),
+ {ok, #state{conn=C}}.
+
+
+handle_call({equery, SQL, Args}, _From, State) ->
+ Reply = pgsql:equery(State#state.conn, SQL, Args),
+ {reply, Reply, State};
+
+handle_call(_Request, _From, State) ->
+ Reply = ok,
+ {reply, Reply, State}.
+
+
+
+handle_cast(_Msg, State) ->
+ {noreply, State}.
+
+handle_info(_Info, State) ->
+ {noreply, State}.
+
+terminate(_Reason, State) ->
+ pgsql:close(State#state.conn).
+
+code_change(_OldVsn, State, _Extra) ->
+ {ok, State}.
+
+
+
+%%--------------------------------------------------------------------
+%%% Internal functions
+%%--------------------------------------------------------------------
View
14 evo/src/evosite_sup.erl
@@ -12,7 +12,7 @@
-include("evo.hrl").
%% API
--export([start_link/1, start_epgsql/5]).
+-export([start_link/1]).
%% Supervisor callbacks
-export([init/1]).
@@ -83,8 +83,8 @@ start(pgsql, Conf) ->
undefined -> [];
PgStartup ->
PgName = ?CONFNAME(Conf, "pgsql"),
- [{PgName, {?MODULE, start_epgsql, [PgName|PgStartup]},
- permanent,5000,worker,[pgsql_connection]}]
+ [{PgName, {evoepgsql, start_link, [PgName|PgStartup]},
+ permanent,5000,worker,[pgsql_connection]}]
end;
@@ -100,7 +100,7 @@ make_loop(Conf) ->
-start_epgsql(Name, Host, User, Pass, Opts) ->
- {ok, C} = gen_fsm:start_link({local, Name}, pgsql_connection, [], []),
- pgsql_connection:connect(C, Host, User, Pass, Opts),
- {ok, C}.
+%start_epgsql(Name, Host, User, Pass, Opts) ->
+% {ok, C} = gen_fsm:start_link({local, Name}, pgsql_connection, [], []),
+% pgsql_connection:connect(C, Host, User, Pass, Opts),
+% {ok, C}.
Please sign in to comment.
Something went wrong with that request. Please try again.