Bier.Guc (bier v0.1.0)

Copy Markdown View Source

Reads and applies the PostgREST response GUCs a function or trigger may set during a request:

  • response.headers — a JSON array of single-key objects, each becoming a response header. The same name may appear twice (e.g. two Set-Cookie), so headers are emitted in order and never folded. A malformed value (anything but an array of single-key string-valued objects) is PGRST111.
  • response.status — overrides the HTTP status. A non-integer / out-of-range value is PGRST112.

The GUCs are transaction-local (set_config(..., true) / SET LOCAL), so read/1 must run on the SAME Postgrex transaction connection that executed the function/mutation, before the transaction ends.

Summary

Functions

Apply parsed GUC headers to conn, preserving order and duplicates. The status override (guc.status) is NOT applied here — the caller must pass it to send_resp so it takes effect — use status/2 to fold it with the default.

Read the two response GUCs on transaction connection tx.

The effective status: the GUC override when present, else default.

Functions

put_headers(conn, arg2)

Apply parsed GUC headers to conn, preserving order and duplicates. The status override (guc.status) is NOT applied here — the caller must pass it to send_resp so it takes effect — use status/2 to fold it with the default.

read(tx)

Read the two response GUCs on transaction connection tx.

Returns {:ok, %{headers: [{name, value}], status: integer | nil}} or {:error, :bad_response_headers_guc} / {:error, :bad_response_status_guc}.

status(arg1, default)

The effective status: the GUC override when present, else default.