Просмотр исходного кода

Drop R16 support; use maps as internal options datastructure

Сергей Прохоров 7 лет назад
Родитель
Сommit
f406a18ba0

+ 0 - 1
.travis.yml

@@ -14,7 +14,6 @@ otp_release:
   - 19.3
   - 18.3
   - 17.5
-  - R16B03-1
 script:
   - make elvis
   - make test

+ 2 - 17
Makefile

@@ -1,17 +1,9 @@
 REBAR = ./rebar3
-ERL_VSN = $(shell erl -eval 'erlang:display(erlang:system_info(otp_release)), halt().'  -noshell)
 
 all: compile
 
 $(REBAR):
-	@case "$(ERL_VSN)" in\
-		"R16"*)\
-			wget https://github.com/erlang/rebar3/releases/download/3.5.2/rebar3 \
-			;;\
-		*)\
-			wget https://s3.amazonaws.com/rebar3/rebar3 \
-			;;\
-	esac
+	wget https://s3.amazonaws.com/rebar3/rebar3
 	chmod +x rebar3
 
 compile: src/epgsql_errcodes.erl $(REBAR)
@@ -30,13 +22,6 @@ dialyzer: compile
 	@$(REBAR) dialyzer
 
 elvis: $(REBAR)
-	@case "$(ERL_VSN)" in\
-		"R16"*)\
-			echo "Elvis is disabled on erl 16"\
-			;;\
-		*)\
-			$(REBAR) as lint lint\
-			;;\
-	esac
+	@$(REBAR) as lint lint
 
 .PHONY: all compile clean test dialyzer elvis

+ 39 - 34
README.md

@@ -57,52 +57,57 @@ see `CHANGES` for full list.
   (thousands of messages).
 
 ## Usage
+
 ### Connect
 
 ```erlang
--type host() :: inet:ip_address() | inet:hostname().
-
--type connect_option() ::
-    {database, DBName     :: string()}             |
-    {port,     PortNum    :: inet:port_number()}   |
-    {ssl,      IsEnabled  :: boolean() | required} |
-    {ssl_opts, SslOptions :: [ssl:ssl_option()]}   | % @see OTP ssl app, ssl_api.hrl
-    {timeout,  TimeoutMs  :: timeout()}            | % default: 5000 ms
-    {async,    Receiver   :: pid() | atom()}       | % process to receive LISTEN/NOTIFY msgs
-    {codecs,   Codecs     :: [{epgsql_codec:codec_mod(), any()}]} |
-    {replication, Replication :: string()}. % Pass "database" to connect in replication mode
-    
--spec connect(host(), string(), string(), [connect_option()] | map())
-        -> {ok, Connection :: connection()} | {error, Reason :: connect_error()}.    
-%% @doc connects to Postgres
-%% where
-%% `Host'     - host to connect to
-%% `Username' - username to connect as, defaults to `$USER'
-%% `Password' - optional password to authenticate with
-%% `Opts'     - proplist or map of extra options
-%% returns `{ok, Connection}' otherwise `{error, Reason}'
-connect(Host, Username, Password, Opts) -> ...
+connect(Opts) -> {ok, Connection :: epgsql:connection()} | {error, Reason :: epgsql:connect_error()}
+    when
+  Opts ::
+    #{host :=     inet:ip_address() | inet:hostname(),
+      username := iodata(),
+      password => iodata(),
+      database => iodata(),
+      port =>     inet:port_number(),
+      ssl =>      boolean() | required,
+      ssl_opts => [ssl:ssl_option()],    % @see OTP ssl app, ssl_api.hrl
+      timeout =>  timeout(),             % socket connect timeout, default: 5000 ms
+      async =>    pid() | atom(),        % process to receive LISTEN/NOTIFY msgs
+      codecs =>   [{epgsql_codec:codec_mod(), any()}]}
+      replication => Replication :: string()} % Pass "database" to connect in replication mode
+    | list().
+
+connect(Host, Username, Password, Opts) -> {ok, C} | {error, Reason}.
 ```
 example:
 ```erlang
-{ok, C} = epgsql:connect("localhost", "username", "psss", [
-    {database, "test_db"},
-    {timeout, 4000}
-]),
+{ok, C} = epgsql:connect("localhost", "username", "psss", #{
+    database => "test_db",
+    timeout => 4000
+}),
 ...
 ok = epgsql:close(C).
 ```
 
-The `{timeout, TimeoutMs}` parameter will trigger an `{error, timeout}` result when the
-socket fails to connect within `TimeoutMs` milliseconds.
+Only `host` and `username` are mandatory, but most likely you would need `database` and `password`.
+
+- `{timeout, TimeoutMs}` parameter will trigger an `{error, timeout}` result when the
+   socket fails to connect within `TimeoutMs` milliseconds.
+- `ssl` if set to `true`, perform an attempt to connect in ssl mode, but continue unencrypted
+  if encryption isn't supported by server. if set to `required` connection will fail if encryption
+  is not available.
+- `ssl_opts` will be passed as is to `ssl:connect/3`
+- `async` see [Server notifications](#server-notifications)
+- `codecs` see [Pluggable datatype codecs](#pluggable-datatype-codecs)
+- `replication` see [Streaming replication protocol](#streaming-replication-protocol)
 
-Options may be passed as map with the same key names, if your VM version supports maps.
+Options may be passed as proplist or as map with the same key names.
 
 Asynchronous connect example (applies to **epgsqli** too):
 
 ```erlang
   {ok, C} = epgsqla:start_link(),
-  Ref = epgsqla:connect(C, "localhost", "username", "psss", [{database, "test_db"}]),
+  Ref = epgsqla:connect(C, "localhost", "username", "psss", #{database => "test_db"}),
   receive
     {C, Ref, connected} ->
         {ok, C};
@@ -221,7 +226,7 @@ receive
 end.
 ```
 
-## Extended Query
+### Extended Query
 
 ```erlang
 {ok, Columns, Rows}        = epgsql:equery(C, "select ...", [Parameters]).
@@ -267,7 +272,7 @@ end.
 `epgsqli:equery(C, Statement, [TypedParameters])` sends same set of messages as
 squery including final `{C, Ref, done}`.
 
-## Prepared Query
+### Prepared Query
 ```erlang
 {ok, Columns, Rows}        = epgsql:prepared_query(C, StatementName, [Parameters]).
 {ok, Count}                = epgsql:prepared_query(C, StatementName, [Parameters]).
@@ -302,7 +307,7 @@ end.
 `epgsqli:prepared_query(C, Statement, [TypedParameters])` sends same set of messages as
 squery including final `{C, Ref, done}`.
 
-## Parse/Bind/Execute
+### Parse/Bind/Execute
 
 ```erlang
 {ok, Statement} = epgsql:parse(C, [StatementName], Sql, [ParameterTypes]).
@@ -360,7 +365,7 @@ All epgsql functions return `{error, Error}` when an error occurs.
 `epgsqla`/`epgsqli` modules' `close` and `sync` functions send `{C, Ref, ok}`.
 
 
-## Batch execution
+### Batch execution
 
 Batch execution is `bind` + `execute` for several prepared statements.
 It uses unnamed portals and `MaxRows = 0`.

+ 13 - 15
rebar.config

@@ -1,5 +1,4 @@
-{erl_opts, [{platform_define, "^[0-9]+", have_maps},
-            {platform_define, "^(1[89])|^([2-9][0-9])", 'FAST_MAPS'}, % Erlang >=18
+{erl_opts, [{platform_define, "^(1[89])|^([2-9][0-9])", 'FAST_MAPS'}, % Erlang >=18
             {platform_define, "^(R|1|20)", 'FUN_STACKTRACE'}]}. % Erlang < 21
 
 {eunit_opts, [verbose]}.
@@ -22,16 +21,15 @@
     {ct_hooks, [epgsql_cth]}
 ]}.
 
-%% See rebar.config.script
-%% {elvis,
-%%   [#{dirs => ["src", "src/*"],
-%%      include_dirs => ["include"],
-%%      filter => "*.erl",
-%%      ruleset => erl_files,
-%%      rules =>
-%%          [{elvis_style, line_length, #{limit => 120}},
-%%           {elvis_style, god_modules, #{limit => 40}},
-%%           {elvis_style, state_record_and_type, disable} % epgsql_sock
-%%          ]}
-%%   ]
-%%  }.
+{elvis,
+  [#{dirs => ["src", "src/*"],
+     include_dirs => ["include"],
+     filter => "*.erl",
+     ruleset => erl_files,
+     rules =>
+         [{elvis_style, line_length, #{limit => 120}},
+          {elvis_style, god_modules, #{limit => 40}},
+          {elvis_style, state_record_and_type, disable} % epgsql_sock
+         ]}
+  ]
+ }.

+ 0 - 19
rebar.config.script

@@ -1,19 +0,0 @@
-%% Elvis config uses maps, but they are not available in Erlang < 17
-case erlang:is_builtin(erlang, is_map, 1) of
-    true ->
-        [{elvis,
-          [maps:from_list(
-             [{dirs, ["src", "src/*"]},
-              {include_dirs, ["include"]},
-              {filter, "*.erl"},
-              {ruleset, erl_files},
-              {rules,
-                 [{elvis_style, line_length, maps:from_list([{limit, 120}])},
-                  {elvis_style, god_modules, maps:from_list([{limit, 40}])},
-                  {elvis_style, state_record_and_type, disable} % epgsql_sock
-                 ]}
-              ])
-          ]
-         } | CONFIG];
-    false -> CONFIG
-end.

+ 31 - 40
src/commands/epgsql_cmd_connect.erl

@@ -27,7 +27,7 @@
                                    | unknown).
 
 -record(connect,
-        {opts :: list(),
+        {opts :: map(),
          auth_fun :: auth_fun() | undefined,
          auth_state :: any() | undefined,
          auth_send :: {integer(), iodata()} | undefined,
@@ -42,18 +42,17 @@
 -define(AUTH_SASL_FINAL, 12).
 
 init({Host, Username, Password, Opts}) ->
-    Opts1 = [{host, Host},
-             {username, Username},
-             {password, Password}
-             | Opts],
+    Opts1 = maps:merge(Opts,
+                       #{host => Host,
+                         username => Username,
+                         password => Password}),
     #connect{opts = Opts1}.
 
 execute(PgSock, #connect{opts = Opts, stage = connect} = State) ->
-    Host = get_val(host, Opts),
-    Username = get_val(username, Opts),
-    %% _ = get_val(password, Opts),
-    Timeout = proplists:get_value(timeout, Opts, 5000),
-    Port = proplists:get_value(port, Opts, 5432),
+    #{host := Host,
+      username := Username} = Opts,
+    Timeout = maps:get(timeout, Opts, 5000),
+    Port = maps:get(port, Opts, 5432),
     SockOpts = [{active, false}, {packet, raw}, binary, {nodelay, true}, {keepalive, true}],
     case gen_tcp:connect(Host, Port, SockOpts, Timeout) of
         {ok, Sock} ->
@@ -67,29 +66,27 @@ execute(PgSock, #connect{opts = Opts, stage = connect} = State) ->
                 inet:getopts(Sock, [recbuf, sndbuf]),
             inet:setopts(Sock, [{buffer, max(RecBufSize, SndBufSize)}]),
 
-            PgSock1 = maybe_ssl(Sock, proplists:get_value(ssl, Opts, false), Opts, PgSock),
+            PgSock1 = maybe_ssl(Sock, maps:get(ssl, Opts, false), Opts, PgSock),
 
             Opts2 = ["user", 0, Username, 0],
-            Opts3 = case proplists:get_value(database, Opts, undefined) of
-                undefined -> Opts2;
-                Database  -> [Opts2 | ["database", 0, Database, 0]]
+            Opts3 = case maps:find(database, Opts) of
+                error -> Opts2;
+                {ok, Database}  -> [Opts2 | ["database", 0, Database, 0]]
             end,
 
-            Replication = proplists:get_value(replication, Opts, undefined),
-            Opts4 = case Replication of
-                        undefined -> Opts3;
-                        Replication  ->
-                            [Opts3 | ["replication", 0, Replication, 0]]
+            {Opts4, PgSock2} =
+                case Opts of
+                    #{replication := Replication}  ->
+                        {[Opts3 | ["replication", 0, Replication, 0]],
+                         epgsql_sock:init_replication_state(PgSock1)};
+                        _ -> {Opts3, PgSock1}
                     end,
-            PgSock2 = case Replication of
-                          undefined -> PgSock1;
-                          _ -> epgsql_sock:init_replication_state(PgSock1)
-                      end,
 
             epgsql_sock:send(PgSock2, [<<196608:?int32>>, Opts4, 0]),
-            PgSock3 = case proplists:get_value(async, Opts, undefined) of
-                          undefined -> PgSock2;
-                          Async -> epgsql_sock:set_attr(async, Async, PgSock2)
+            PgSock3 = case Opts of
+                          #{async := Async} ->
+                              epgsql_sock:set_attr(async, Async, PgSock2);
+                          _ -> PgSock2
                       end,
             {ok, PgSock3, State#connect{stage = maybe_auth}};
         {error, Reason} = Error ->
@@ -104,11 +101,11 @@ maybe_ssl(S, false, _, PgSock) ->
     epgsql_sock:set_net_socket(gen_tcp, S, PgSock);
 maybe_ssl(S, Flag, Opts, PgSock) ->
     ok = gen_tcp:send(S, <<8:?int32, 80877103:?int32>>),
-    Timeout = proplists:get_value(timeout, Opts, 5000),
+    Timeout = maps:get(timeout, Opts, 5000),
     {ok, <<Code>>} = gen_tcp:recv(S, 1, Timeout),
     case Code of
         $S  ->
-            SslOpts = proplists:get_value(ssl_opts, Opts, []),
+            SslOpts = maps:get(ssl_opts, Opts, []),
             case ssl:connect(S, SslOpts, Timeout) of
                 {ok, S2}        ->
                     epgsql_sock:set_net_socket(ssl, S2, PgSock);
@@ -167,14 +164,14 @@ auth_handle(Data, PgSock, #connect{auth_fun = Fun, auth_state = AuthSt} = St) ->
 
 %% AuthenticationCleartextPassword
 auth_cleartext(init, _AuthState, #connect{opts = Opts}) ->
-    Password = get_val(password, Opts),
+    Password = maps:get(password, Opts),
     {send, ?PASSWORD, [Password, 0], undefined};
 auth_cleartext(_, _, _) -> unknown.
 
 %% AuthenticationMD5Password
 auth_md5(init, Salt, #connect{opts = Opts}) ->
-    User = get_val(username, Opts),
-    Password = get_val(password, Opts),
+    User = maps:get(username, Opts),
+    Password = maps:get(password, Opts),
     Digest1 = hex(erlang:md5([Password, User])),
     Str = ["md5", hex(erlang:md5([Digest1, Salt])), 0],
     {send, ?PASSWORD, Str, undefined};
@@ -182,14 +179,14 @@ auth_md5(_, _, _) -> unknown.
 
 %% AuthenticationSASL
 auth_scram(init, undefined, #connect{opts = Opts}) ->
-    User = get_val(username, Opts),
+    User = maps:get(username, Opts),
     Nonce = epgsql_scram:get_nonce(16),
     ClientFirst = epgsql_scram:get_client_first(User, Nonce),
     SaslInitialResponse = [?SCRAM_AUTH_METHOD, 0, <<(iolist_size(ClientFirst)):?int32>>, ClientFirst],
     {send, ?SASL_ANY_RESPONSE, SaslInitialResponse, {auth_request, Nonce}};
 auth_scram(<<?AUTH_SASL_CONTINUE:?int32, ServerFirst/binary>>, {auth_request, Nonce}, #connect{opts = Opts}) ->
-    User = get_val(username, Opts),
-    Password = get_val(password, Opts),
+    User = maps:get(username, Opts),
+    Password = maps:get(password, Opts),
     ServerFirstParts = epgsql_scram:parse_server_first(ServerFirst, Nonce),
     {ClientFinalMessage, ServerProof} = epgsql_scram:get_client_final(ServerFirstParts, Nonce, User, Password),
     {send, ?SASL_ANY_RESPONSE, ClientFinalMessage, {server_final, ServerProof}};
@@ -242,12 +239,6 @@ handle_message(?ERROR, Err, Sock, #connect{stage = Stage} = _State) when Stage =
 handle_message(_, _, _, _) ->
     unknown.
 
-
-get_val(Key, Proplist) ->
-    Val = proplists:get_value(Key, Proplist),
-    (Val =/= undefined) orelse error({required_option, Key}),
-    Val.
-
 hex(Bin) ->
     HChar = fun(N) when N < 10 -> $0 + N;
                (N) when N < 16 -> $W + N

+ 23 - 26
src/epgsql.erl

@@ -27,7 +27,7 @@
          standby_status_update/3,
          start_replication/5,
          start_replication/6,
-         to_proplist/1]).
+         to_map/1]).
 -export([handle_x_log_data/5]).                 % private
 
 -export_type([connection/0, connect_option/0, connect_opts/0,
@@ -57,7 +57,6 @@
     {codecs,   Codecs     :: [{epgsql_codec:codec_mod(), any()}]} |
     {replication, Replication :: string()}. % Pass "database" to connect in replication mode
 
--ifdef(have_maps).
 -type connect_opts() ::
         [connect_option()]
       | #{host => host(),
@@ -68,12 +67,9 @@
           ssl => boolean() | required,
           ssl_opts => [ssl:ssl_option()],
           timeout => timeout(),
-          async => pid(),
+          async => pid() | atom(),
           codecs => [{epgsql_codec:codec_mod(), any()}],
           replication => string()}.
--else.
--type connect_opts() :: [connect_option()].
--endif.
 
 -type connect_error() :: epgsql_cmd_connect:connect_error().
 -type query_error() :: #error{}.
@@ -129,10 +125,10 @@
 -spec connect(connect_opts())
         -> {ok, Connection :: connection()} | {error, Reason :: connect_error()}.
 connect(Settings0) ->
-    Settings = to_proplist(Settings0),
-    Host = proplists:get_value(host, Settings, "localhost"),
-    Username = proplists:get_value(username, Settings, os:getenv("USER")),
-    Password = proplists:get_value(password, Settings, ""),
+    Settings = to_map(Settings0),
+    Host = maps:get(host, Settings, "localhost"),
+    Username = maps:get(username, Settings, os:getenv("USER")),
+    Password = maps:get(password, Settings, ""),
     connect(Host, Username, Password, Settings).
 
 connect(Host, Opts) ->
@@ -148,7 +144,7 @@ connect(Host, Username, Opts) ->
 %% `Host'     - host to connect to
 %% `Username' - username to connect as, defaults to `$USER'
 %% `Password' - optional password to authenticate with
-%% `Opts'     - proplist of extra options
+%% `Opts'     - proplist or map of extra options
 %% returns `{ok, Connection}' otherwise `{error, Reason}'
 connect(Host, Username, Password, Opts) ->
     {ok, C} = epgsql_sock:start_link(),
@@ -157,7 +153,7 @@ connect(Host, Username, Password, Opts) ->
 -spec connect(connection(), host(), string(), string(), connect_opts())
         -> {ok, Connection :: connection()} | {error, Reason :: connect_error()}.
 connect(C, Host, Username, Password, Opts0) ->
-    Opts = to_proplist(Opts0),
+    Opts = to_map(Opts0),
     %% TODO connect timeout
     case epgsql_sock:sync_command(
            C, epgsql_cmd_connect, {Host, Username, Password, Opts}) of
@@ -170,7 +166,7 @@ connect(C, Host, Username, Password, Opts0) ->
     end.
 
 maybe_update_typecache(C, Opts) ->
-    maybe_update_typecache(C, proplists:get_value(replication, Opts), proplists:get_value(codecs, Opts)).
+    maybe_update_typecache(C, maps:get(replication, Opts, undefined), maps:get(codecs, Opts, undefined)).
 
 maybe_update_typecache(C, undefined, undefined) ->
     %% TODO: don't execute 'update_type_cache' when `codecs` is undefined.
@@ -368,27 +364,27 @@ with_transaction(C, F) ->
                {ensure_committed, boolean()} |
                {begin_opts, iodata()}].
 with_transaction(C, F, Opts0) ->
-    Opts = to_proplist(Opts0),
-    Begin = case proplists:get_value(begin_opts, Opts) of
-                undefined -> <<"BEGIN">>;
-                BeginOpts ->
-                    [<<"BEGIN ">> | BeginOpts]
+    Opts = to_map(Opts0),
+    Begin = case Opts of
+                #{begin_opts := BeginOpts} ->
+                    [<<"BEGIN ">> | BeginOpts];
+                _ -> <<"BEGIN">>
             end,
     try
         {ok, [], []} = squery(C, Begin),
         R = F(C),
         {ok, [], []} = squery(C, <<"COMMIT">>),
-        case proplists:get_value(ensure_committed, Opts, false) of
-            true ->
+        case Opts of
+            #{ensure_committed := true} ->
                 {ok, CmdStatus} = get_cmd_status(C),
                 (commit == CmdStatus) orelse error({ensure_committed_failed, CmdStatus});
-            false -> ok
+            _ -> ok
         end,
         R
     catch
         ?WITH_STACKTRACE(Type, Reason, Stack)
             squery(C, "ROLLBACK"),
-            case proplists:get_value(reraise, Opts, true) of
+            case maps:get(reraise, Opts, true) of
                 true ->
                     erlang:raise(Type, Reason, Stack);
                 false ->
@@ -435,7 +431,8 @@ start_replication(Connection, ReplicationSlot, Callback, CbInitState, WALPositio
     start_replication(Connection, ReplicationSlot, Callback, CbInitState, WALPosition, []).
 
 %% @private
-to_proplist(List) when is_list(List) ->
-    List;
-to_proplist(Map) ->
-    maps:to_list(Map).
+-spec to_map([{any(), any()}] | map()) -> map().
+to_map(Map) when is_map(Map) ->
+    Map;
+to_map(List) when is_list(List) ->
+    maps:from_list(List).

+ 7 - 7
src/epgsqla.erl

@@ -29,10 +29,10 @@ start_link() ->
     epgsql_sock:start_link().
 
 connect(Opts) ->
-    Settings = epgsql:to_proplist(Opts),
-    Host = proplists:get_value(host, Settings, "localhost"),
-    Username = proplists:get_value(username, Settings, os:getenv("USER")),
-    Password = proplists:get_value(password, Settings, ""),
+    Settings = epgsql:to_map(Opts),
+    Host = maps:get(host, Settings, "localhost"),
+    Username = maps:get(username, Settings, os:getenv("USER")),
+    Password = maps:get(password, Settings, ""),
     connect(Host, Username, Password, Settings).
 
 connect(Host, Opts) ->
@@ -46,9 +46,9 @@ connect(Host, Username, Password, Opts) ->
     connect(C, Host, Username, Password, Opts).
 
 -spec connect(epgsql:connection(), inet:ip_address() | inet:hostname(),
-              string(), string(), [epgsql:connect_option()]) -> reference().
+              string(), string(), epgsql:connect_opts()) -> reference().
 connect(C, Host, Username, Password, Opts) ->
-    Opts1 = epgsql:to_proplist(Opts),
+    Opts1 = epgsql:to_map(Opts),
     complete_connect(
       C, cast(C, epgsql_cmd_connect, {Host, Username, Password, Opts1}), Opts1).
 
@@ -149,7 +149,7 @@ complete_connect(C, Ref, Opts) ->
         %% If we connect, then try and update the type cache.  When
         %% all is said and done, pass the result along as a message.
         {C, Ref, connected} ->
-            case proplists:get_value(codecs, Opts) of
+            case maps:get(codecs, Opts, undefined) of
                 undefined ->
                     {ok, _} = epgsql:update_type_cache(C);
                 [_|_] = Codecs ->

+ 6 - 6
src/epgsqli.erl

@@ -28,10 +28,10 @@ start_link() ->
     epgsql_sock:start_link().
 
 connect(Opts) ->
-    Settings = epgsql:to_proplist(Opts),
-    Host = proplists:get_value(host, Settings, "localhost"),
-    Username = proplists:get_value(username, Settings, os:getenv("USER")),
-    Password = proplists:get_value(password, Settings, ""),
+    Settings = epgsql:to_map(Opts),
+    Host = maps:get(host, Settings, "localhost"),
+    Username = maps:get(username, Settings, os:getenv("USER")),
+    Password = maps:get(password, Settings, ""),
     connect(Host, Username, Password, Settings).
 
 connect(Host, Opts) ->
@@ -45,9 +45,9 @@ connect(Host, Username, Password, Opts) ->
     connect(C, Host, Username, Password, Opts).
 
 -spec connect(epgsql:connection(), inet:ip_address() | inet:hostname(),
-              string(), string(), [epgsql:connect_option()]) -> reference().
+              string(), string(), epgsql:connect_opts()) -> reference().
 connect(C, Host, Username, Password, Opts) ->
-    Opts1 = epgsql:to_proplist(Opts),
+    Opts1 = epgsql:to_map(Opts),
     epgsqla:complete_connect(
       C, incremental(C, epgsql_cmd_connect, {Host, Username, Password, Opts1}), Opts1).
 

+ 2 - 12
test/epgsql_SUITE.erl

@@ -30,14 +30,6 @@ init_per_suite(Config) ->
 all() ->
     [{group, M} || M <- modules()].
 
--ifdef(have_maps).
--define(MAPS_TESTS, [
-    connect_map
-]).
--else.
--define(MAPS_TESTS, []).
--endif.
-
 groups() ->
     Groups = [
         {connect, [parrallel], [
@@ -51,8 +43,8 @@ groups() ->
             connect_with_invalid_password,
             connect_with_ssl,
             connect_with_client_cert,
-            connect_to_closed_port
-            | ?MAPS_TESTS
+            connect_to_closed_port,
+            connect_map
         ]},
         {types, [parallel], [
             numeric_type,
@@ -263,7 +255,6 @@ connect_with_client_cert(Config) ->
         [{ssl, true}, {ssl_opts, [{keyfile, File("epgsql.key")},
                                   {certfile, File("epgsql.crt")}]}]).
 
--ifdef(have_maps).
 connect_map(Config) ->
     {Host, Port} = epgsql_ct:connection_data(Config),
     Module = ?config(module, Config),
@@ -279,7 +270,6 @@ connect_map(Config) ->
     Module:close(C),
     epgsql_ct:flush(),
     ok.
--endif.
 
 connect_to_closed_port(Config) ->
     {Host, Port} = epgsql_ct:connection_data(Config),

+ 2 - 2
test/epgsql_cast.erl

@@ -35,8 +35,8 @@ connect(Host, Username, Password, Opts) ->
     await_connect(Ref, Opts).
 
 await_connect(Ref, Opts0) ->
-    Opts = epgsql_cth:to_proplist(Opts0),
-    Timeout = proplists:get_value(timeout, Opts, 5000),
+    Opts = epgsql:to_map(Opts0),
+    Timeout = maps:get(timeout, Opts, 5000),
     receive
         {C, Ref, connected} ->
             {ok, C};

+ 1 - 7
test/epgsql_cth.erl

@@ -3,8 +3,7 @@
 -export([
          init/2,
          terminate/1,
-         pre_init_per_suite/3,
-         to_proplist/1
+         pre_init_per_suite/3
         ]).
 
 -include_lib("common_test/include/ct.hrl").
@@ -245,8 +244,3 @@ ts_add({Mega, Sec, Micro}, Timeout) ->
     {V div 1000000000000,
      V div 1000000 rem 1000000,
      V rem 1000000}.
-
-to_proplist(List) when is_list(List) ->
-    List;
-to_proplist(Map) ->
-    maps:to_list(Map).

+ 2 - 2
test/epgsql_incremental.erl

@@ -33,8 +33,8 @@ connect(Host, Username, Password, Opts) ->
     await_connect(Ref, Opts).
 
 await_connect(Ref, Opts0) ->
-    Opts = epgsql_cth:to_proplist(Opts0),
-    Timeout = proplists:get_value(timeout, Opts, 5000),
+    Opts = epgsql:to_map(Opts0),
+    Timeout = maps:get(timeout, Opts, 5000),
     receive
         {C, Ref, connected} ->
             {ok, C};

+ 1 - 2
test/epgsql_replication_SUITE.erl

@@ -69,8 +69,7 @@ replication_test_run(Config, Callback) ->
                 fun(C2) ->
                     [{ok, 1},{ok, 1}] = Module:squery(C2,
                         "insert into test_table1 (id, value) values (5, 'five');delete from test_table1 where id = 5;")
-                end,
-                "epgsql_test_db1"),
+                end),
 
             Module:start_replication(C, "epgsql_test", Callback, {C, self()}, "0/0"),
             ok = receive_replication_msgs(