Skip to content

Function: defineSchema()

defineSchema<T>(tables): T

Defined in: core/src/schema/schema.ts:23

Identity function that groups tables into a schema.

Kept explicit (rather than passing tables around as loose records) so IDEs, migration tooling, and the runtime engine can find “the schema” as a single named binding.

Also validates that every entry’s object key matches its table(name) argument. A silent mismatch — e.g. defineSchema({ tasks: table("todos", ...) }) — used to compile fine but blew up at runtime: db.select().from(tasks) looked up “todos” in the SQL layer but the schema registry only had “tasks”, so the mutator threw unknown table and the sync handler quietly advanced last_mutation_id past the failed mutation. Alpha (dogfood) hit this and traced a “done flag flickers on then reverts” symptom back to the mismatch — expensive debug for what should be a defineSchema check.

T extends Record<string, AnyTable>

T

T