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
-type equery_result() :: epgsql_cmd_equery:response() | error().
-type error() :: {error, query_error()} | epgsql_sock:error().
-type query_error() :: epgsql:query_error() | query_timeout | connection_down | paused | term().
-type query_result() :: squery_result() | equery_result().
-type squery_result() :: epgsql_cmd_squery:response() | error().
Functions
-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.
-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.
-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.
-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.
-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.
Threshold above which we do an automatic explain of traced queries.