Skip to content

DB Changes

The DBChanges component is used to listen to changes on a table in the Supabase Realtime service. It uses a svelte store to store and forward the data received from the channel to wrapped components.

This component must be a child of the SupabaseApp component to work.

Props

Prop nameDescriptionDefault value
channelNameThe name of the channel to listen to changes on.'any'
eventThe type of event to listen to changes for. Can be one of "*", "INSERT", "UPDATE", or "DELETE"."*"
schemaThe name of the schema to listen to changes on."*"
tableThe name of the table to listen to changes on. If null, listens to changes on all tables in the schema.null
filterA filter expression to apply to the changes. If null, no filter is applied.null

Slots

  • default: The default slot is rendered with the latest changes. It has access to the following props:

    PropertyDescription
    payloadThe latest changes to the database table.
    errorAn error object if there was an error listening to changes.
    realtimeThe Supabase RealtimeClient instance.
    channelThe Supabase RealtimeChannel instance.
  • loading: The loading slot is rendered while the component is waiting for the initial changes to load.

Usage

<script lang="ts">
import { DbChanges } from 'supasveltekit';
</script>
<DbChanges channelName="db" event="*" schema="public" table="test" let:payload>
{#if error !== null}
<div>{error.message}</div>
{/if}
{#if payload !== null}
<p>Last change received: >{payload?.eventType ?? "none"}</strong></p>
{/if}
</DbChanges>