Database & ORM
We use Postgres (Neon) and Drizzle ORM for type-safe database interactions.
Schema Definition
Your database schema is defined in src/lib/schema.ts.
import { pgTable, text, timestamp, uuid } from "drizzle-orm/pg-core";
export const users = pgTable("user", {
id: text("id").primaryKey(),
name: text("name"),
email: text("email").notNull(),
});
Migrations
Whenever you change src/lib/schema.ts, you must push the changes to your database.
Run this command:
npx drizzle-kit push
Querying Data
You can query data in any Server Component or Server Action:
import { db } from "@/lib/db";
import { users } from "@/lib/schema";
const allUsers = await db.select().from(users);