Builds the configuration for a TanStack DB collection backed by a Postgres table. Pass the result to createCollection() from @tanstack/react-db.
alter publication supabase_realtime add table todos;.The Postgres table this collection reads from and writes to.
The primary key column or columns for the table. Must match the table's primary key.
A schema used to validate and type each row. Works with any [Standard Schema](https://standardschema.dev) library, such as Zod or Valibot.
The Supabase client instance to query and subscribe through.
An existing TanStack Query client to share, if you already use one. If omitted, a shared global client is used.
Keep the collection in sync across clients using Supabase Realtime. Defaults to `false`.
Experimental. Apply server-side filtering to Realtime updates instead of filtering on the client. Only applies when `realtime` is `true`. Queries that can't be expressed as a Realtime filter, like `or(...)`, fall back to the unfiltered subscription. Defaults to `false`.
import { createCollection } from '@tanstack/react-db'
import { supabaseCollectionOptions } from '@supabase-labs/tanstack-db'
import { z } from 'zod'
const todosSchema = z.object({
id: z.string(),
title: z.string(),
completed: z.boolean(),
})
export const todos = createCollection(
supabaseCollectionOptions({
tableName: 'todos',
keys: ['id'],
schema: todosSchema,
supabase,
realtime: true,
})
)