Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup edocs. Fixes #213 #214

Merged
merged 3 commits into from
Feb 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
_build
rebar3
datadir/
doc/*
!doc/overview.edoc
!doc/*.md
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ matrix:
script:
- '[ "$TRAVIS_OTP_RELEASE" = "18.3" ] || make elvis' # TODO: remove the guard when OTP18 support is dropped
- make test
- make edoc
- make dialyzer
7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ compile: src/epgsql_errcodes.erl $(REBAR)

clean: $(REBAR)
@$(REBAR) clean
@rm -f doc/*.html
@rm -f doc/erlang.png
@rm -f doc/stylesheet.css
@rm -f doc/edoc-info

src/epgsql_errcodes.erl:
./generate_errcodes_src.sh > src/epgsql_errcodes.erl
Expand All @@ -34,4 +38,7 @@ dialyzer: compile
elvis: $(REBAR)
@$(REBAR) as lint lint

edoc: $(REBAR)
@$(REBAR) edoc

.PHONY: all compile clean common-test eunit cover test dialyzer elvis
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ item will be `{error, #error{}}` and no more results will be produced.

## Data Representation

Data representation may be configured using [pluggable datatype codecs](pluggable_types.md),
Data representation may be configured using [pluggable datatype codecs](doc/pluggable_types.md),
so following is just default mapping:

PG type | Representation
Expand Down Expand Up @@ -618,15 +618,15 @@ Parameter's value may change during connection's lifetime.

## Streaming replication protocol

See [streaming.md](streaming.md).
See [streaming.md](doc/streaming.md).

## Pluggable commands

See [pluggable_commands.md](pluggable_commands.md)
See [pluggable_commands.md](doc/pluggable_commands.md)

## Pluggable datatype codecs

See [pluggable_types.md](pluggable_types.md)
See [pluggable_types.md](doc/pluggable_types.md)

## Mailing list

Expand Down
57 changes: 57 additions & 0 deletions doc/overview.edoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
@title epgsql - PostgreSQL driver for Erlang, internal documentation
@doc
This document is made mostly as internal documentation. It can be useful
if you plan to contribute some patches to epgsql, want to implement
custom datatypes or commands or to better understand epgsql internals.

End-user interface is described in <a href="https://github.com/epgsql/epgsql#readme">README.md</a>.

== Interfaces ==
Epgsql has 3 end-user API interfaces:

<ul>
<li>{@link epgsql} - synchronous</li>
<li>{@link epgsqla} - asynchronous</li>
<li>{@link epgsqli} - incremental</li>
</ul>

== Internals ==

All 3 interfaces communicate with {@link epgsql_sock} gen_server, which holds all
the connection state. While `epgsql_sock' holds all the state, it doesn't know
much about Client-Server communication protocol.
All the communication logic between epgsql and PostgreSQL server is implemented
as a {@section Commands} and `epgsql_sock' acts as an executor for those commands.

PostgreSQL binary communication protocol is represented by 2 modules:
<ul>
<li>{@link epgsql_wire} - codecs for on-wire communication protocol messages</li>
<li>{@link epgsql_binary} - interface to PostgreSQL binary data encoding protocol(see {@section Datatypes})</li>
</ul>

`epgsql_sock' holds an internal state of `epgsql_binary' codecs as well. The
main contents of this state is the mapping between PostgreSQL unique numeric
datatype IDs (OIDs) and callbacks which will be used to decode this datatype.
This mapping is handled by {@link epgsql_oid_db} module and is populated at
connection set-up time by {@link epgsql_cmd_connect}.

Most of the connection initialization (network connection, authentication, codecs)
is performed by {@link epgsql_cmd_connect} command, wich is just a regualr command
(but quite complex one) and can be replaced by own implementation if needed.

== Commands ==

Client can execute a number of built-in commands as well as define their own.
See {@link epgsql_command} and all the `epgsql_cmd_*' pages.
There exists a <a href="pluggable_commands.md">manual</a> that explains how to
implement your own command.

== Datatypes ==

Epgsql supports both PostgreSQL <a href="https://www.postgresql.org/docs/current/protocol-overview.html#PROTOCOL-FORMAT-CODES">text and binary</a>
data encodings to transfer the data (query placeholder parameters and result rows).
There are a bunch of built-in codecs and it's possible to
implement custom ones as well as fine-tune some of built-ins.
See {@link epgsql_codec} and all the `epgsql_codec_*' pages for more details.
There exists a <a href="pluggable_types.md">manual</a> that explains how to
implement your own datatype codec.
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 2 additions & 1 deletion rebar.config
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
{eunit_opts, [verbose]}.

{cover_enabled, true}.
{cover_print_enabled, true}.

{edoc_opts, [{preprocess, true}]}.

{profiles, [
{test, [
Expand Down
11 changes: 11 additions & 0 deletions src/commands/epgsql_cmd_batch.erl
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
%% @doc Execute multiple extended queries in a single network round-trip
%%
%% There are 2 kinds of interface:
%% <ol>
%% <li>To execute multiple queries, each with it's own `statement()'</li>
%% <li>To execute multiple queries, but by binding different parameters to the
%% same `statement()'</li>
%% </ol>
%% ```
%% > {Bind
%% < BindComplete
%% > Execute
%% < DataRow*
%% < CommandComplete}*
%% > Sync
%% < ReadyForQuery
%% '''
-module(epgsql_cmd_batch).
-behaviour(epgsql_command).
-export([init/1, execute/2, handle_message/4]).
Expand Down Expand Up @@ -57,6 +67,7 @@ execute(Sock, #batch{batch = Batch,
types = Types}} = State) ->
Codec = epgsql_sock:get_codec(Sock),
BinFormats = epgsql_wire:encode_formats(Columns),
%% TODO: build some kind of encoder and reuse it for each batch item
Commands =
lists:foldr(
fun(Parameters, Acc) ->
Expand Down
6 changes: 6 additions & 0 deletions src/commands/epgsql_cmd_bind.erl
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
%% @doc Binds placeholder parameters to prepared statement
%%
%% ```
%% > Bind
%% < BindComplete
%% '''
%% @see epgsql_cmd_parse
%% @see epgsql_cmd_execute
-module(epgsql_cmd_bind).
-behaviour(epgsql_command).
-export([init/1, execute/2, handle_message/4]).
Expand Down
4 changes: 4 additions & 0 deletions src/commands/epgsql_cmd_close.erl
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
%% @doc Closes statement / portal
%%
%% ```
%% > Close
%% < CloseComplete
%% '''
-module(epgsql_cmd_close).
-behaviour(epgsql_command).
-export([init/1, execute/2, handle_message/4]).
Expand Down
6 changes: 4 additions & 2 deletions src/commands/epgsql_cmd_connect.erl
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
%%% @doc Connects to the server and performs all the necessary handshakes.
%%%
%%% Special kind of command - it's exclusive: no other commands can run until
%%% this one finishes.
%%% It also uses some 'private' epgsql_sock's APIs
%%% It also uses some "private" epgsql_sock's APIs
%%%
-module(epgsql_cmd_connect).
-behaviour(epgsql_command).
Expand Down Expand Up @@ -105,7 +107,7 @@ opts_hide_password(Opts) -> Opts.


%% @doc this function wraps plaintext password to a lambda function, so, if
%% epgsql_sock process crashes when executing `connect` command, password will
%% epgsql_sock process crashes when executing `connect' command, password will
%% not appear in a crash log
-spec hide_password(iodata()) -> fun( () -> iodata() ).
hide_password(Password) when is_list(Password);
Expand Down
6 changes: 5 additions & 1 deletion src/commands/epgsql_cmd_describe_portal.erl
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
%% > Describe
%% @doc Asks the server to provide description of portal's results columns
%%
%% ```
%% > Describe(PORTAL)
%% < RowDescription | NoData
%% '''
-module(epgsql_cmd_describe_portal).
-behaviour(epgsql_command).
-export([init/1, execute/2, handle_message/4]).
Expand Down
9 changes: 7 additions & 2 deletions src/commands/epgsql_cmd_describe_statement.erl
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
%% Almost the same as "parse"
%% > Describe
%% @doc Asks server to provide input parameter and result rows information.
%%
%% Almost the same as {@link epgsql_cmd_parse}.
%%
%% ```
%% > Describe(STATEMENT)
%% < ParameterDescription
%% < RowDescription | NoData
%% '''
-module(epgsql_cmd_describe_statement).
-behaviour(epgsql_command).
-export([init/1, execute/2, handle_message/4]).
Expand Down
9 changes: 9 additions & 0 deletions src/commands/epgsql_cmd_equery.erl
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
%% @doc Performs 2nd stage of
%% <a href="https://www.postgresql.org/docs/current/protocol-flow.html#PROTOCOL-FLOW-EXT-QUERY">
%% extended query protocol.</a>
%%
%% Takes prepared `statement()' and bind-parameters for placeholders and produces
%% query results.
%% ```
%% > Bind
%% < BindComplete
%% > Execute
Expand All @@ -7,6 +14,8 @@
%% < CloseComplete
%% > Sync
%% < ReadyForQuery
%% '''
%% @see epgsql_cmd_parse
-module(epgsql_cmd_equery).
-behaviour(epgsql_command).
-export([init/1, execute/2, handle_message/4]).
Expand Down
8 changes: 8 additions & 0 deletions src/commands/epgsql_cmd_execute.erl
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
%% @doc Executes a portal.
%%
%% It's possible to tell the server to only return limited number of rows by
%% providing non-zero `MaxRows' parameter.
%% ```
%% > Execute
%% < DataRow*
%% < CommandComplete | PortalSuspended
%% '''
%% @see epgsql_cmd_parse
%% @see epgsql_cmd_bind
-module(epgsql_cmd_execute).
-behaviour(epgsql_command).
-export([init/1, execute/2, handle_message/4]).
Expand Down
4 changes: 4 additions & 0 deletions src/commands/epgsql_cmd_parse.erl
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
%% @doc Asks server to parse SQL query and send information aboud bind-parameters and result columns.
%%
%% ```
%% > Parse
%% < ParseComplete
%% > Describe
%% < ParameterDescription
%% < RowDescription | NoData
%% '''
-module(epgsql_cmd_parse).
-behaviour(epgsql_command).
-export([init/1, execute/2, handle_message/4]).
Expand Down
6 changes: 5 additions & 1 deletion src/commands/epgsql_cmd_prepared_query.erl
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
%% Almost the same as equery, but don't execute 'CLOSE'
%% @doc Almost the same as equery, but don't execute 'CLOSE'
%%
%% So, statement can be reused multiple times.
%% ```
%% > Bind
%% < BindComplete
%% > Execute
%% < DataRow*
%% < CommandComplete
%% > Sync
%% < ReadyForQuery
%% '''
-module(epgsql_cmd_prepared_query).
-behaviour(epgsql_command).
-export([init/1, execute/2, handle_message/4]).
Expand Down
7 changes: 7 additions & 0 deletions src/commands/epgsql_cmd_squery.erl
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
%% @doc Executes SQL query(es) using
%% <a href="https://www.postgresql.org/docs/current/protocol-flow.html#id-1.10.5.7.4">
%% simple query protocol</a>
%%
%% Squery can not have placeholders.
%% Squery may contain many semicolon-separated queries
%% ```
%% > Query
%% < (RowDescription?
%% < DataRow*
Expand All @@ -8,6 +14,7 @@
%% > Query when len(strip(Query)) == 0
%% < EmptyQueryResponse
%% < ReadyForQuery
%% '''
-module(epgsql_cmd_squery).
-behaviour(epgsql_command).
-export([init/1, execute/2, handle_message/4]).
Expand Down
5 changes: 5 additions & 0 deletions src/commands/epgsql_cmd_start_replication.erl
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
%% @doc Requests server to start sending replication packets
%%
%% See {@link epgsql:connect/1} `replication' parameter.
%% ```
%% > SimpleQuery "START_REPLICATION ..."
%% < CopyBothResponse | Error
%% '''
-module(epgsql_cmd_start_replication).
-behaviour(epgsql_command).
-export([init/1, execute/2, handle_message/4]).
Expand Down
5 changes: 5 additions & 0 deletions src/commands/epgsql_cmd_sync.erl
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
%% @doc Synchronize client and server states for multi-command combinations
%%
%% Should be executed if APIs start to return `{error, sync_required}'.
%% ```
%% > Sync
%% < ReadyForQuery
%% '''
-module(epgsql_cmd_sync).
-behaviour(epgsql_command).
-export([init/1, execute/2, handle_message/4]).
Expand Down
2 changes: 1 addition & 1 deletion src/commands/epgsql_cmd_update_type_cache.erl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
%% Special command. Executes Squery over pg_type table and updates codecs.
%% @doc Special command. Executes Squery over pg_type table and updates codecs.
-module(epgsql_cmd_update_type_cache).
-behaviour(epgsql_command).
-export([init/1, execute/2, handle_message/4]).
Expand Down
7 changes: 5 additions & 2 deletions src/datatypes/epgsql_codec_boolean.erl
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
%%% @doc
%%% Codec for `bool'.
%%%
%%% `unknown' is represented by `null'.
%%% https://www.postgresql.org/docs/current/static/datatype-boolean.html
%%% $PG$/src/backend/utils/adt/bool.c
%%% <ul>
%%% <li>[https://www.postgresql.org/docs/current/static/datatype-boolean.html]</li>
%%% <li>$PG$/src/backend/utils/adt/bool.c</li>
%%% </ul>
%%% @end
%%% Created : 12 Oct 2017 by Sergey Prokhorov <me@seriyps.ru>

Expand Down
17 changes: 12 additions & 5 deletions src/datatypes/epgsql_codec_bpchar.erl
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
%%% @doc
%%% Codec for `bpchar', `char' (CHAR(N), char).
%%% ```SELECT 1::char''' ```SELECT 'abc'::char(10)'''
%%% For 'text', 'varchar' see epgsql_codec_text.erl.
%%% https://www.postgresql.org/docs/10/static/datatype-character.html
%%% $PG$/src/backend/utils/adt/varchar.c
%%% Codec for blank-padded fixed-size character type
%%%
%%% `CHAR' (single-byte) is represented as `byte()';
%%% `CHARACTER(N) / CHAR(N)' as binary string
%%%
%%% <code>SELECT 1::char;</code> <code>SELECT 'abc'::char(10)</code>
%%%
%%% For 'text', 'varchar' see {@link epgsql_codec_text}.
%%% <ul>
%%% <li>[https://www.postgresql.org/docs/10/static/datatype-character.html]</li>
%%% <li>$PG$/src/backend/utils/adt/varchar.c</li>
%%% </ul>
%%% @end
%%% Created : 12 Oct 2017 by Sergey Prokhorov <me@seriyps.ru>

Expand Down
15 changes: 11 additions & 4 deletions src/datatypes/epgsql_codec_datetime.erl
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
%%% @doc
%%% Codec for `time', `timetz', `date', `timestamp', `timestamptz', `interval'
%%% https://www.postgresql.org/docs/current/static/datatype-datetime.html
%%% $PG$/src/backend/utils/adt/timestamp.c // `timestamp', `timestamptz', `interval'
%%% $PG$/src/backend/utils/adt/datetime.c // helpers
%%% $PG$/src/backend/utils/adt/date.c // `time', `timetz', `date'
%%%
%%% It supports both integer and float datetime representations (see
%%% [https://www.postgresql.org/docs/current/runtime-config-preset.html#GUC-INTEGER-DATETIMES]).
%%% But float representation support might be eventually removed.
%%%
%%% <ul>
%%% <li>[https://www.postgresql.org/docs/current/static/datatype-datetime.html]</li>
%%% <li>$PG$/src/backend/utils/adt/timestamp.c // `timestamp', `timestamptz', `interval'</li>
%%% <li>$PG$/src/backend/utils/adt/datetime.c // helpers</li>
%%% <li>$PG$/src/backend/utils/adt/date.c // `time', `timetz', `date'</li>
%%% </ul>
%%% @end
%%% Created : 12 Oct 2017 by Sergey Prokhorov <me@seriyps.ru>

Expand Down