Schema-to-Type Mapping
How table definitions become TypeScript types.
From Table Definition to Row Type
A type-safe ORM lets you describe a database table once and derive its TypeScript row type automatically. You never hand-write the row shape; it is computed from the column definitions.
In this lesson we use a Drizzle-style pgTable as the running example.
Defining a Table
A table is an object mapping column names to column builders. Each builder encodes a SQL type plus modifiers like notNull or primaryKey.
import { pgTable, serial, text, integer, boolean } from "drizzle-orm/pg-core";
export const users = pgTable("users", {
id: serial("id").primaryKey(),
name: text("name").notNull(),
age: integer("age"),
isAdmin: boolean("is_admin").notNull(),
});All lessons in this course
- Schema-to-Type Mapping
- Type-Safe Query Construction
- Inferring Query Result Shapes
- Relations and Joins with Types