Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion rebar.config
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,7 @@

{ct_opts, [{ct_hooks, [cth_surefire]}]}.

{dialyzer, [{warnings, [no_unknown]}]}.
{dialyzer, [
{plt_apps, top_level_deps},
{plt_extra_apps, [ssl]}
]}.
11 changes: 6 additions & 5 deletions src/pgo.erl
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
-export_type([result/0,
error/0,
pool_config/0,
decode_fun/0]).
decode_fun/0,
decode_option/0]).

-type result() :: #{command := atom(),
num_rows := integer() | table,
Expand Down Expand Up @@ -67,7 +68,7 @@
idle_interval => integer(),

%% gen_tcp socket options
socket_options => [gen_tcp:socket_option()],
socket_options => [gen_tcp:option()],

%% defaults for options used at query time
queue => boolean(),
Expand Down Expand Up @@ -209,16 +210,16 @@ with_conn(Conn, Fun) ->
end.

%% @doc Returns a connection from the pool.
-spec checkout(atom()) -> {ok, pgo_pool:pool_ref(), pgo_pool:conn()} | {error, any()}.
-spec checkout(atom()) -> {ok, pgo_pool:ref(), pgo_pool:conn()} | {error, any()}.
checkout(Pool) ->
pgo_pool:checkout(Pool, []).

-spec checkout(atom(), [pool_option()]) -> {ok, pgo_pool:pool_ref(), pgo_pool:conn()} | {error, any()}.
-spec checkout(atom(), [pool_option()]) -> {ok, pgo_pool:ref(), pgo_pool:conn()} | {error, any()}.
checkout(Pool, Options) ->
pgo_pool:checkout(Pool, Options).

%% @doc Return a checked out connection to its pool
-spec checkin(pgo_pool:pool_ref(), pgo_pool:conn()) -> ok.
-spec checkin(pgo_pool:ref(), pgo_pool:conn()) -> ok.
checkin(Ref, Conn) ->
pgo_pool:checkin(Ref, Conn, []).

Expand Down
2 changes: 1 addition & 1 deletion src/pgo_connection.erl
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ ping(Pid, Holder, _Conn) ->
stop(Pid, Holder, _Conn) ->
gen_statem:cast(Pid, {stop, Holder}).

-spec disconnect(pid(), ets:tid(), {error, atom()}, pg_pool:conn()) -> ok.
-spec disconnect(pid(), ets:tid(), {error, atom()}, pgo_pool:conn()) -> ok.
disconnect(Pid, Holder, _Err, _Conn) ->
%% maybe log Err?
gen_statem:cast(Pid, {disconnect, Holder}).
Expand Down
12 changes: 7 additions & 5 deletions src/pgo_handler.erl
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ extended_query(Socket, Query, Parameters) ->
extended_query(Socket, Query, Parameters, Timings) when is_map(Timings) ->
extended_query(Socket, Query, Parameters, [], Timings).

-spec extended_query(#conn{}, iodata(), list(), pgo:decode_opts(), map()) -> pgo:result().
%% TODO
%% -spec extended_query(#conn{}, iodata(), list(), pgo:decode_option(), map()) -> pgo:result().
extended_query(Socket, Query, Parameters, DecodeOptions, _Timings) ->
DecodeFun = proplists:get_value(decode_fun, DecodeOptions, undefined),
extended_query(Socket, Query, Parameters, DecodeOptions, DecodeFun, []).
Expand Down Expand Up @@ -243,7 +244,7 @@ auth_scram(Conn, Options) ->
Error
end.

-spec scram_client_first(pgo_scram:nonce(), #conn{}, maps:map()) -> {ok, term()} | {error, #error_response{}} | {error, term()}.
-spec scram_client_first(pgo_scram:nonce(), #conn{}, #{user => iodata()}) -> {ok, term()} | {error, #error_response{}} | {error, term()}.
scram_client_first(Nonce, #conn{socket_module=SocketModule,
socket=Socket,
pool=Pool}, Options) ->
Expand All @@ -258,7 +259,7 @@ scram_client_first(Nonce, #conn{socket_module=SocketModule,
SendError
end.

-spec scram_client_final(pgo_scram:nonce(), binary(), #conn{}, maps:map()) -> {{ok, term()}, binary()} | {{error, term()}, binary()} | {error, term()}.
-spec scram_client_final(pgo_scram:nonce(), binary(), #conn{}, #{user => iodata(), password => iodata()}) -> {{ok, term()}, binary()} | {{error, term()}, binary()} | {error, term()}.
scram_client_final(Nonce, ServerFirst, #conn{socket_module=SocketModule,
socket=Socket,
pool=Pool}, Options) ->
Expand Down Expand Up @@ -334,7 +335,8 @@ setup_finish(Conn=#conn{socket_module=SocketModule,
%% set_succeeded_or_within_failed_transaction({error, {error, _} = Error}) ->
%% error:is_in_failed_sql_transaction(Error).

-spec extended_query(#conn{}, iodata(), list(), pgo:decode_aopts(), any(), list()) -> pgo:result().
%% TODO
%% -spec extended_query(#conn{}, iodata(), list(), pgo:decode_option(), any(), list()) -> pgo:result().
extended_query(Conn=#conn{socket=Socket,
socket_module=SocketModule,
pool=Pool}, Query, Parameters, DecodeOptions, PerRowFun, Acc0) ->
Expand Down Expand Up @@ -396,7 +398,7 @@ encode_bind_describe_execute(Conn, Parameters, ParameterDataTypes) ->
%% requires_statement_description(_Parameters) ->
%% true. %pgo_protocol:bind_requires_statement_description(Parameters).

-spec receive_loop(extended_query_loop_state(), pgo:decode_fun(), list(), list(), pgo:conn())
-spec receive_loop(extended_query_loop_state(), pgo:decode_fun(), list(), list(), #conn{})
-> pgo:result().
receive_loop(LoopState, DecodeFun, Acc0, DecodeOptions, Conn=#conn{socket=Socket,
socket_module=SocketModule}) ->
Expand Down
6 changes: 4 additions & 2 deletions src/pgo_internal.hrl
Original file line number Diff line number Diff line change
Expand Up @@ -282,14 +282,16 @@
}).
-record(empty_query_response, {}).
-record(error_response, {
fields :: [pgsql_error:pgsql_error_and_mention_field()] | #{error_field() => binary()}
fields %% TODO
%% :: [pgsql_error:pgsql_error_and_mention_field()] | #{error_field() => binary()}
}).
-record(function_call_response, {
value :: null | iodata()
}).
-record(no_data, {}).
-record(notice_response, {
fields :: [pgsql_error:pgsql_error_and_mention_field()] | #{error_field() => binary()}
fields %% TODO
%% :: [pgsql_error:pgsql_error_and_mention_field()] | #{error_field() => binary()}
}).
-record(notification_response, {
procid :: pgsql_procid(),
Expand Down
5 changes: 3 additions & 2 deletions src/pgo_protocol.erl
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ encode_parse_message(PreparedStatementName, Query, DataTypes) ->
%%--------------------------------------------------------------------
%% @doc Encode a bind message.
%%
-spec encode_bind_message(pg_pool:conn(), iodata(), iodata(), [any()], [pg_types:oid()]) -> iolist().
-spec encode_bind_message(#conn{}, iodata(), iodata(), [any()], [pg_types:oid()]) -> iolist().
encode_bind_message(Conn=#conn{pool=Pool}, PortalName, StatementName, Parameters, ParametersDataTypes) ->
ParametersCount = length(Parameters),
ParametersCountBin = <<ParametersCount:16/integer>>,
Expand Down Expand Up @@ -511,7 +511,8 @@ decode_error_and_notice_message_fields0(<<FieldType, Rest0/binary>>, Acc) ->
end;
decode_error_and_notice_message_fields0(Bin, _Acc) -> {error, {badarg, Bin}}.

-spec decode_error_and_mention_field_type(byte()) -> pgsql_error:pgsql_error_and_mention_field_type().
%% TODO
%% -spec decode_error_and_mention_field_type(byte()) -> pgsql_error:pgsql_error_and_mention_field_type().
decode_error_and_mention_field_type($S) -> severity;
decode_error_and_mention_field_type($C) -> code;
decode_error_and_mention_field_type($M) -> message;
Expand Down