z_db_pgsql (zotonic_core v1.0.0-rc.17)

Postgresql pool worker. Supervises a database connection, ensures it is connected. The connection is given to the query process. If the query process doesn't return the connection, then the connection is reset.

The connection is given to the query process to prevent extra copying of query results between the worker and the query process.

Summary

Functions

Query with parameters, the query is interrupted if it takes longer than Timeout msec.

Batch Query, the query is interrupted if it takes longer than Timeout msec.

This function MUST NOT be used, but currently is required by the install / upgrade routines. Can only be called from inside a z_db:transaction/2.

After a connection is fetched using get_raw_connection/1, use this to release the connection again. Otherwise the connection can not be used for other SQL queries. This must be called from inside the same transaction as get_raw_connection/1 was called.

Simple query without parameters, the query is interrupted if it takes longer than Timeout msec.

Threshold above which we do an automatic explain of traced queries.

Types

equery_result/0

-type equery_result() :: epgsql_cmd_equery:response() | error().

error/0

-type error() :: {error, query_error()} | epgsql_sock:error().

query_error/0

-type query_error() :: epgsql:query_error() | query_timeout | connection_down | paused | term().

query_result/0

-type query_result() :: squery_result() | equery_result().

squery_result/0

-type squery_result() :: epgsql_cmd_squery:response() | error().

Functions

build_connect_options(DatabaseName, Args)

code_change(OldVsn, State, Extra)

ensure_all_started()

equery(Worker, Sql, Parameters, Timeout)

-spec equery(Worker, Sql, Parameters, Timeout) -> Result
                when
                    Worker :: pid(),
                    Sql :: string() | binary(),
                    Parameters :: list(),
                    Timeout :: pos_integer(),
                    Result :: equery_result().

Query with parameters, the query is interrupted if it takes longer than Timeout msec.

execute_batch(Worker, Sql, Batch, Timeout)

-spec execute_batch(Worker, Sql, Batch, Timeout) -> Result
                       when
                           Worker :: pid(),
                           Sql :: string() | binary(),
                           Batch :: [list()],
                           Timeout :: pos_integer(),
                           Result :: {ok, [equery_result()]} | {error, connection_down | term()}.

Batch Query, the query is interrupted if it takes longer than Timeout msec.

get_raw_connection(Context)

-spec get_raw_connection(Context) -> {ok, ConnPid} | {error, Reason}
                            when Context :: z:context(), ConnPid :: pid(), Reason :: term().

This function MUST NOT be used, but currently is required by the install / upgrade routines. Can only be called from inside a z_db:transaction/2.

handle_call(Cmd, From, State)

handle_cast(Msg, State)

handle_info(Info, State)

init(Args)

is_connection_alive(Worker)

-spec is_connection_alive(Worker) -> boolean() when Worker :: pid().

pool_get_connection(Context)

-spec pool_get_connection(Context) -> {ok, Conn} | {error, Reason}
                             when Context :: z:context(), Conn :: pid(), Reason :: term().

pool_return_connection(Worker, Context)

-spec pool_return_connection(Worker, Context) -> ok | {error, Reason}
                                when Worker :: pid(), Context :: z:context(), Reason :: term().

release_raw_connection(Context)

-spec release_raw_connection(Context) -> ok | {error, Reason}
                                when Context :: z:context(), Reason :: term().

After a connection is fetched using get_raw_connection/1, use this to release the connection again. Otherwise the connection can not be used for other SQL queries. This must be called from inside the same transaction as get_raw_connection/1 was called.

squery(Worker, Sql, Timeout)

-spec squery(Worker, Sql, Timeout) -> Result
                when
                    Worker :: pid(),
                    Sql :: string() | binary(),
                    Timeout :: pos_integer(),
                    Result :: squery_result().

Simple query without parameters, the query is interrupted if it takes longer than Timeout msec.

start_link(Args)

Threshold above which we do an automatic explain of traced queries.

terminate(Reason, State)

test_connection(Args)

-spec test_connection(list()) -> ok | {error, term()}.