The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
chore: add Realtime Postgres Changes guide
Wen Bo Xie4e7c6ffef8c0
diff --git a/apps/reference/docs/guides/realtime/postgres_changes.mdx b/apps/reference/docs/guides/realtime/postgres_changes.mdxnew file mode 100644index 00000000000..bb0703cfb65--- /dev/null+++ b/apps/reference/docs/guides/realtime/postgres_changes.mdx@@ -0,0 +1,83 @@+---+id: postgres_changes+title: Postgres Changes+description: Getting started with Realtime's Postgres Changes feature+---++Supabase Postgres Changes enable clients to listen Postgres database events, specifically INSERT, UPDATE, and DELETE events.++Clients can elect to get changes for all tables in the public schema, a specific table, or a specific column's value.++The postgres changes functionality is supported by supabase-js v2 release candidate.++To listen to all events on all tables in the public schema:++```js+const { createClient } = require('@supabase/supabase-js')++const supabase = createClient(+ process.env.SUPABASE_URL,+ process.env.SUPABASE_KEY+)++/*+ The name of the channel can be set to any string.+ Event can be either INSERT, UPDATE, DELETE, or * for all events.+*/+const channel = supabase+ .channel('db-changes')+ .on('postgres_changes', { event: '*', schema: '*' }, (payload) =>+ console.log(payload)+ )+ .subscribe()+```++To listen to INSERT events on the messages table in the public schema:++```js+// Setup++const channel = supabase+ .channel('db-changes')+ .on(+ 'postgres_changes',+ { event: 'INSERT', schema: 'public', table: 'messages' },+ (payload) => console.log(payload)+ )+ .subscribe()+```++To listen to UPDATE events only when a specific column matches a value:++```js+// Setup++const channel = supabase+ .channel('db-changes')+ .on(+ 'postgres_changes',+ { event: 'UPDATE', schema: 'public', table: 'messages', filter: 'id=eq.1' },+ (payload) => console.log(payload)+ )+ .subscribe()+```++Clients can also mix and match and listen to different events and schema/tables/filters:++```js+// Setup++const channel = supabase+ .channel('db-changes')+ .on(+ 'postgres_changes',+ { event: '*', schema: 'public', table: 'messages', filter: 'id=eq.23' },+ (payload) => console.log(payload)+ )+ .on(+ 'postgres_changes',+ { event: 'INSERT', schema: 'public', table: 'users' },+ (payload) => console.log(payload)+ )+ .subscribe()+```diff --git a/apps/reference/nav/_referenceSidebars.js b/apps/reference/nav/_referenceSidebars.jsindex 74ef6ca7783..9395bb9eb81 100644--- a/apps/reference/nav/_referenceSidebars.js+++ b/apps/reference/nav/_referenceSidebars.js@@ -84,7 +84,11 @@ const sidebars = {type: 'category',label: 'Realtime',collapsed: true,- items: ['guides/realtime/broadcast', 'guides/realtime/presence'],+ items: [+ 'guides/realtime/broadcast',+ 'guides/realtime/presence',+ 'guides/realtime/postgres_changes'+ ],},{type: 'category',