Subscribe to real-time database updates
masterPostgres.js supports logical replication to subscribe to insert, update, and delete operations.
Prerequisites:
- Create a publication in your database (e.g.,
CREATE PUBLICATION alltables FOR ALL TABLES). - Set
wal_level = logicalinpostgresql.conf. - Connect using a replication or superuser.
Usage:
Initialize the client with the publications option, then call sql.subscribe.
Subscription Pattern:
operation:schema.table=primary_key
operation:*,insert,update, ordelete(defaults to*)schema: defaults topublictable: defaults to*primary_key: filter by specific row ID.