epgsql and normalises its return
values into a unified rdbms_result() type.
PostgreSQL driver layer — wraps epgsql and normalises its return
values into a unified rdbms_result() type.
{ok, Count} — plain DML (no RETURNING){ok, Count, Cols, Rows} — DML + RETURNING clause{ok, Cols, Rows} — SELECT{error, #error{}} — driver error{updated, Count} — plain DML{updated, Count, Rows} — DML + RETURNING{selected, Rows} — SELECT{error, duplicate_key} — unique constraint violation
(SQLSTATE 23505){error, Reason} — any other errorrdbms_result() = rdbms:rdbms_result()
| connect/1 | Open a new PostgreSQL connection. |
| disconnect/1 | Close a PostgreSQL connection. |
| query/3 | Run a parameterised query and normalise the result. |
| squery/2 | Run a simple (non-parameterised) statement. |
| transaction/2 | Run Fun(Conn) inside a BEGIN/COMMIT block. |
connect(Opts::proplists:proplist()) -> {ok, epgsql:connection()} | {error, term()}
Opts: Proplist of connection options
(host, port, username, password, database, ssl).
returns: {ok, Connection} or {error, Reason}.
Open a new PostgreSQL connection.
Connection options are taken from a proplist with the same shape as thepostgres application environment key. Missing keys fall back
to safe defaults (localhost:5432, user postgres).
disconnect(Conn::epgsql:connection()) -> ok
Conn: The epgsql connection to close.
returns: ok (always).
Close a PostgreSQL connection.
Wrapsepgsql:close/1 in catch so callers don't have to worry
about a connection that has already died.
query(Conn::epgsql:connection(), SQL::iodata(), Params::[term()]) -> rdbms_result()
Conn: The epgsql connection.
SQL: SQL with $1, $2... placeholders.
Params: Bind parameters matching the placeholders.
returns: A normalised rdbms_result().
Run a parameterised query and normalise the result.
squery(Conn::epgsql:connection(), SQL::iodata()) -> term()
Conn: The epgsql connection.
SQL: The SQL statement (iodata).
returns: The raw epgsql result.
Run a simple (non-parameterised) statement.
Used for DDL and transaction control (BEGIN, COMMIT, ROLLBACK).
The raw epgsql result is returned unchanged.
transaction(Conn::epgsql:connection(), Fun::fun((epgsql:connection()) -> T)) -> {ok, T} | {error, term()}
Conn: The epgsql connection.
Fun: Function of arity 1 taking the connection.
returns: {ok, T} on COMMIT, or {error, Reason} on ROLLBACK.
Run Fun(Conn) inside a BEGIN/COMMIT block.
Fun should return its result directly on success. To abort and
trigger a ROLLBACK, Fun returns {rollback, Reason} — this is
preferred over throw because it avoids the stacktrace cost on the
common conflict path. Throws are still caught for compatibility;
unexpected exceptions are re-raised after rolling back.
Generated by EDoc