0Pricing
TypeScript Academy · Lesson

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

  1. Schema-to-Type Mapping
  2. Type-Safe Query Construction
  3. Inferring Query Result Shapes
  4. Relations and Joins with Types
← Back to TypeScript Academy