Skip to content

SyncTableInput

SyncTableInput<TName, TColumns, TOmittedColumns> = object

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

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:376

CDC insert-apply policy (ADR-0045). Default "insert" — a CDC insert is a plain INSERT, so a genuine PK collision must surface (the ADR-0014 collision-surfacing invariant; a synced cache table is server-authoritative and a duplicate insert is a real bug). Set "upsert" only when this table legitimately receives locally-DERIVED provisional rows — e.g. a local trigger on another synced table inserts a provisional row here, and the server independently creates the same row so its CDC insert would collide (23505). With "upsert", server CDC inserts are applied idempotently as INSERT … ON CONFLICT (pk) DO UPDATE; the authoritative server row overwrites the provisional local row. Declare the exception here, where it lives — do not weaken the invariant repo-wide.


optional clientProjection?: SyncTableInputProjection<TColumns, TOmittedColumns>

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


optional conflictPolicy?: ConflictPolicy

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

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


optional consistencyGroup?: string

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

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


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

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

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:387


makeColumns: () => TColumns

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

TColumns


optional mode?: TableMode

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

"readonly"

optional policies?: PgPolicy[]

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

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:365

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:408

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


optional rowClass?: string

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

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:348

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


optional serverProjection?: ServerProjectionSpec

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

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


optional shape?: ShapeSpecInputFor<TColumns>

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


optional subscription?: SubscriptionTiming

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

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


tableName: TName

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


optional writeMode?: WriteMode

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

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