Anton Lebedevich 13 лет назад
Родитель
Сommit
f3cfc8992e
3 измененных файлов с 28 добавлено и 6 удалено
  1. 18 4
      README
  2. 5 1
      src/apgsql.erl
  3. 5 1
      src/ipgsql.erl

+ 18 - 4
README

@@ -13,7 +13,7 @@ Difference highlights (see CHANGES for full list):
 
 * Known problems
 
-  Timeout supplied at connect time will work only as connect timeout not query timeout.
+  Timeout supplied at connect time works as socket connect timeout not query timeout.
   SSL performance degrades if driver process has large inbox (thousands of messages).
 
 
@@ -31,13 +31,27 @@ Difference highlights (see CHANGES for full list):
     + {ssl,      Atom}       true | false | required
     + {ssl_opts, List}       see ssl application docs in OTP
     + {timeout,  Integer}    milliseconds, defaults to 5000
-    + {async,    Pid}        see Asynchronous Messages section
+    + {async,    Pid}        see Server Notifications section
 
   {ok, C} = pgsql:connect("localhost", "username", [{database, "test_db"}]).
   ok = pgsql:close(C).
 
   The timeout parameter will trigger an {error, timeout} result when the
-  server fails to respond within Timeout milliseconds.
+  socket fails to connect within Timeout milliseconds.
+
+  Asynchronous connection example (applies to ipgsql too):
+
+  {ok, C} = apgsql:start_link(),
+  Ref = apgsql:connect(C, "localhost", "username", [{database, "test_db"}]),
+  receive
+    {C, Ref, connected} ->
+      {ok, C};
+    {C, Ref, Error = {error, _}} ->
+      Error;
+    {'EXIT', C, _Reason} ->
+      {error, closed}
+  end.
+
 
 * Simple Query
 
@@ -136,7 +150,7 @@ Difference highlights (see CHANGES for full list):
   closed                                - connection was closed
   sync_required                         - error occured and pgsql:sync must be called
 
-* Asynchronous Messages
+* Server Notifications
 
   PostgreSQL may deliver two types of asynchronous message: "notices" in response
   to notice and warning messages generated by the server, and "notifications" which

+ 5 - 1
src/apgsql.erl

@@ -2,7 +2,8 @@
 
 -module(apgsql).
 
--export([connect/2, connect/3, connect/4, connect/5,
+-export([start_link/0,
+         connect/2, connect/3, connect/4, connect/5,
          close/1,
          get_parameter/2,
          squery/2,
@@ -20,6 +21,9 @@
 
 %% -- client interface --
 
+start_link() ->
+    pgsql_sock:start_link().
+
 connect(Host, Opts) ->
     connect(Host, os:getenv("USER"), "", Opts).
 

+ 5 - 1
src/ipgsql.erl

@@ -2,7 +2,8 @@
 
 -module(ipgsql).
 
--export([connect/2, connect/3, connect/4, connect/5,
+-export([start_link/0,
+         connect/2, connect/3, connect/4, connect/5,
          close/1,
          get_parameter/2,
          squery/2,
@@ -20,6 +21,9 @@
 
 %% -- client interface --
 
+start_link() ->
+    pgsql_sock:start_link().
+
 connect(Host, Opts) ->
     connect(Host, os:getenv("USER"), "", Opts).