PgRest.Write.Modify (PgRest v0.2.0)

Copy Markdown View Source

Serves PATCH /<table>?<filters> and DELETE /<table>?<filters>, on the pipeline in PgRest.Write.

The filters (and logic trees) of the query string select the rows. They are planned like a read's, so a typo (?idd=eq.1) is a 42703 and a column outside readable: a 42501, before any SQL, and compiled onto the mutation target by PgRest.SQL.Write.update/5 and delete/4: on the table itself for the identity scope (PostgREST's shape, which also serves tables without a primary key), through the scope and FOR UPDATE otherwise.

  • Authorization. The operation (:update or :delete), plus :read when the request has any filter, a count or return=representation: filters and counts are a read channel.
  • require_filters_for_mutations (default true): a request with no filter is a 400 21000 (UPDATE requires a WHERE clause, DELETE requires a WHERE clause), as with Supabase's pg-safeupdate. A PATCH that sets no column is exempt: it touches no row.
  • PATCH payload. One object (PgRest.Write.Payload.build_update/5). Without a custom changeset the supplied keys (or columns=) are set as sent. With one, the columns set are the changeset's final changes (it runs once; see PgRest.Write.Payload): an absent or uncast key is untouched, and a value equal to the struct default is set only when the changeset casts with force_changes: true. A payload column outside the resource's writable set is a 42501.
  • Write check. An updated row must still be visible through the scope, else 42501 and a rollback, in the form PgRest.Write uses for inserts. A DELETE has no check.
  • Response. 204 with Content-Range (PgRest.Responder.mutation/6), or 200 with the rows for return=representation. Accept: application/vnd.pgrst.object+json requires exactly one row (else 406 and a rollback). limit, offset, columns (for DELETE) do not select the rows and are ignored.

Differences from PostgREST

PATCH arrays with several objects return PGRST102 instead of applying one arbitrarily. Embedded mutation logic trees are rejected, and embedded pagination on minimal mutations returns PGRST108 rather than being ignored.

Summary

Functions

Runs the PATCH (:update) or DELETE (:delete) and sends the response.

Functions

run(conn, opts, config, request, context, kind)

@spec run(Plug.Conn.t(), map(), map(), PgRest.Request.t(), map(), :update | :delete) ::
  Plug.Conn.t()

Runs the PATCH (:update) or DELETE (:delete) and sends the response.