Skip to content

SyncTableInput

SyncTableInput<TName, TColumns, TOmittedColumns> = object

Defined in: packages/contracts/src/registry.ts:367

Input for defineSyncTable. Supply tableName + makeColumns — the Drizzle table (and, for readwrite mode, the read-model view) are created internally.

Access the built objects via .table and .view on the returned entry.

TName extends string

TColumns extends Record<string, ColumnBuilderBase>

TOmittedColumns extends readonly ColumnKeys<TColumns>[] = []

optional applyMode?: "insert" | "upsert"

Defined in: packages/contracts/src/registry.ts:410

Backfill conflict policy (ADR-0045). Default "insert" — the initial load assumes an empty table (fresh subscription or post-must-refetch re-snapshot) and takes the fast path, COPY or a plain multi-row INSERT, neither of which can express ON CONFLICT. Set "upsert" only when this table legitimately receives locally-DERIVED provisional rows a backfill could land on top of — e.g. a local trigger on another synced table inserts a provisional row here, and the server independently creates the same row (23505). Steady-state changes are unaffected: the engine emits upsert, so they apply as INSERT … ON CONFLICT (pk) DO UPDATE for every table. See SyncTableEntry.applyMode.


optional clientProjection?: SyncTableInputProjection<TColumns, TOmittedColumns>

Defined in: packages/contracts/src/registry.ts:418


optional conflictPolicy?: ConflictPolicy

Defined in: packages/contracts/src/registry.ts:427

Conflict policy (ADR-0015): what happens to a stale write on this table. Required for writable tables — defineSyncTable/defineSyncRegistry reject a writable table without one. See ConflictPolicy.


optional consistencyGroup?: string

Defined in: packages/contracts/src/registry.ts:433

Bind this table into a consistency group (ADR-0009 decision 2): grouped tables sync as one set of streams and commit atomically. Omit for the default singleton group. See SyncTableEntry.consistencyGroup.


optional extras?: (self) => PgTableExtraConfigValue[]

Defined in: packages/contracts/src/registry.ts:381

Extra constraints or indexes on the server-side Postgres table (unique, index, etc.). Receives the built column map — same signature as pgTable’s third argument. Not applied to localTable.

PgBuildExtraConfigColumns<TColumns>

PgTableExtraConfigValue[]


optional governance?: SyncTableInputGovernance<TColumns>

Defined in: packages/contracts/src/registry.ts:421


makeColumns: () => TColumns

Defined in: packages/contracts/src/registry.ts:373

TColumns


optional mode?: TableMode

Defined in: packages/contracts/src/registry.ts:385

"readonly"

optional policies?: PgPolicy[]

Defined in: packages/contracts/src/registry.ts:375

RLS policies (or other table extras) attached to the Postgres table.


optional primaryKey?: string[] | { columns: string[]; name: string; }

Defined in: packages/contracts/src/registry.ts:400

THE primary key of the server table — the single source of truth for its physical PRIMARY KEY constraint. defineSyncTable emits it as the constraint, named `${tableName}_pkey` (matching Postgres’s inline-PK default, so existing consumer databases see no rename churn) unless the object form overrides name.

Defaults to ["id"]. Use an array with multiple entries for composite keys, or the object form { name, columns } to name the constraint.

A single-column key MAY equivalently be declared via the column’s own .primaryKey() (idiomatic drizzle); it must match this spec, and emission is then skipped because the column already carries the constraint. A table-level primaryKey(...) in extras/policies is REJECTED — declare the key here instead.


optional retention?: Retention

Defined in: packages/contracts/src/registry.ts:442

Retention (ADR-0021): persistent (default) | ephemeral. See SyncTableEntry.retention.


optional rowClass?: string

Defined in: packages/contracts/src/registry.ts:416

Consumer-defined row classification (ADR-0052) — see SyncTableEntry.rowClass. Required (and checked against the declared set) when the registry declares SyncRegistryDefinition.rowClasses; unconstrained otherwise.


optional schema?: PgSchemaType

Defined in: packages/contracts/src/registry.ts:383

Place the table in this schema (e.g. for perf-lab schemed tables).


optional serverProjection?: ServerProjectionSpec

Defined in: packages/contracts/src/registry.ts:420

Server-side response-path projection (e.g. rowTransform). Server authority, not client shape.


optional shape?: ShapeSpecInputFor<TColumns>

Defined in: packages/contracts/src/registry.ts:417


optional subscription?: SubscriptionTiming

Defined in: packages/contracts/src/registry.ts:438

Subscription timing (ADR-0021): eager (default) | lazy. See SyncTableEntry.subscription.


tableName: TName

Defined in: packages/contracts/src/registry.ts:372


optional writeMode?: WriteMode

Defined in: packages/contracts/src/registry.ts:446

Write-mode (ADR-0022): optimistic (default) | pessimistic. See SyncTableEntry.writeMode.