rdbms_worker
/ rdbms_pgsql stack.
Public RDBMS API — thin facade over the poolboy / rdbms_worker
/ rdbms_pgsql stack.
All functions check out a connection from the rdbms_pool poolboy
pool and execute synchronously in the caller's process via
gen_server:call/2.
{selected, [tuple()]} — rows from a SELECT{updated, non_neg_integer()} — affected-row count from DML{updated, non_neg_integer(), [tuple()]} — DML with RETURNING{error, duplicate_key} — unique constraint violation
(PostgreSQL SQLSTATE 23505) translated to a stable atom{error, term()} — any other driver errorrdbms_result() = {selected, [tuple()]} | {updated, non_neg_integer()} | {updated, non_neg_integer(), [tuple()]} | {error, duplicate_key | term()}
| sql_query/1 | Execute a parameterised SQL statement with no bind parameters. |
| sql_query/2 | Execute a parameterised SQL statement with bind parameters. |
| squery/1 | Execute a simple (non-parameterised) SQL statement. |
| transaction/1 | Run Fun(Conn) inside a single PostgreSQL transaction. |
sql_query(SQL::iodata()) -> rdbms_result()
SQL: The SQL statement (iodata).
returns: A normalised rdbms_result().
Execute a parameterised SQL statement with no bind parameters.
Equivalent tosql_query(SQL, []).
sql_query(SQL::iodata(), Params::[term()]) -> rdbms_result()
SQL: The SQL statement, with $1, $2... placeholders.
Params: A list of values matching the placeholders.
returns: A normalised rdbms_result().
Execute a parameterised SQL statement with bind parameters.
The statement is sent throughepgsql:equery/3 and the result is
normalised into a uniform shape (see module doc).
squery(SQL::iodata()) -> term()
SQL: The SQL statement (iodata).
returns: The raw epgsql result.
Execute a simple (non-parameterised) SQL statement.
Used for DDL (CREATE TABLE, CREATE INDEX, ...) where parameter binding is not supported by the protocol. The raw epgsql return value is passed through unchanged so callers can pattern-match on[{ok, _}, {ok, _}, ...] for multi-statement scripts.
transaction(Fun::fun((epgsql:connection()) -> T)) -> {ok, T} | {error, term()}
Fun: Function of arity 1 taking the epgsql connection.
returns: {ok, T} on COMMIT (where T is Funs return value),
or {error, Reason} on ROLLBACK.
Run Fun(Conn) inside a single PostgreSQL transaction.
Fun receives the raw epgsql connection. Use
rdbms_pgsql:query/3 inside the fun for normalised results.
Throwing any term inside Fun triggers a ROLLBACK; the thrown value
is returned as {error, Reason}. Returning {rollback, Reason}
is preferred over throw — it avoids stacktrace cost for the common
conflict path.
Generated by EDoc