Track the relations a stream announces and turn positional tuples into row maps.
pgoutput identifies tables by OID and sends column values
positionally, with a Relation message (see
ebifriedrice.postlog.pgoutput) arriving before the first change
that references a table — and again whenever its definition
changes. A consumer keeps the latest relation per OID in a map and
resolves changes against it.
Key-only before-images (updates that changed a replica-identity column, and deletes on tables without REPLICA IDENTITY FULL) arrive full-width with NULL in every non-identity column; rows below pick out the identity columns. Full tuples carry every column.
Rows are maps from column name (string) to value, because column names come from the database and stay data here.
Track the relations a stream announces and turn positional tuples into row maps. pgoutput identifies tables by OID and sends column values positionally, with a Relation message (see [[ebifriedrice.postlog.pgoutput]]) arriving before the first change that references a table — and again whenever its definition changes. A consumer keeps the latest relation per OID in a map and resolves changes against it. Key-only before-images (updates that changed a replica-identity column, and deletes on tables without REPLICA IDENTITY FULL) arrive full-width with NULL in every non-identity column; rows below pick out the identity columns. Full tuples carry every column. Rows are maps from column name (string) to value, because column names come from the database and stay data here.
(apply-message cache {:keys [relation-id] :as relation})Fold a decoded Relation message into the relation cache.
Fold a decoded Relation message into the relation cache.
(resolve-relation cache relation-id)The cached relation for relation-id, or ex-info. A stream is
malformed if a change references a relation it never announced.
The cached relation for `relation-id`, or ex-info. A stream is malformed if a change references a relation it never announced.
(shape-change cache change)(shape-change cache change {:keys [value-decoder]})Reshape a decoded insert/update/delete/truncate message (resolved
against cache) into the change maps this library delivers:
{:op :insert :schema "public" :table "users" :after {"id" "1"}}
{:op :update ... :before {"id" "1"} :after {"id" "2"}}
{:op :delete ... :before {"id" "1"}}
{:op :truncate :tables ["public.users" ...] :cascade? false
:restart-identity? false}
:before is nil unless the server sent an old image; on default
replica identity it holds key columns only. TOASTed values the
server skipped appear as [[pg/unchanged-toast]]. opts:
:value-decoder fn of a column's type-oid and its raw value -- text (string) or binary (bytes) depending on the stream's format -- returning the decoded value; raw values pass through when absent. Other values (nil, TOAST markers) are never passed to it.
Reshape a decoded insert/update/delete/truncate message (resolved
against `cache`) into the change maps this library delivers:
```clojure
{:op :insert :schema "public" :table "users" :after {"id" "1"}}
{:op :update ... :before {"id" "1"} :after {"id" "2"}}
{:op :delete ... :before {"id" "1"}}
{:op :truncate :tables ["public.users" ...] :cascade? false
:restart-identity? false}
```
`:before` is nil unless the server sent an old image; on default
replica identity it holds key columns only. TOASTed values the
server skipped appear as [[pg/unchanged-toast]]. `opts`:
:value-decoder fn of a column's type-oid and its raw value --
text (string) or binary (bytes) depending on the
stream's format -- returning the decoded value;
raw values pass through when absent. Other values
(nil, TOAST markers) are never passed to it.cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |