PostgreSQL & Prisma
Relational data, type-safe
Store and query relational data with PostgreSQL, the powerful open-source database β and access it type-safely from TypeScript with Prisma ORM.
PostgreSQL & Prisma Setup
Get a Postgres database and connect to it type-safely with Prisma.
Get a Postgres database
# Create a free database at https://neon.tech (or run Postgres locally/Docker)What it does
You need a running Postgres server. Neon gives you a free serverless one with a connection string.
Why you need it
Prisma needs a real database to connect to; a hosted one avoids local install headaches.
Alternatives: Local Postgres, Docker (`postgres` image), Supabase, Railway.
Install Prisma
npm install prisma @prisma/client
npx prisma initWhat it does
Installs the Prisma CLI and client and scaffolds a `schema.prisma` plus a `.env`.
Why you need it
Prisma turns your schema into a fully typed database client.
Define your schema & migrate
npx prisma migrate dev --name initWhat it does
Describe your tables as models, then create the tables in the database with a migration.
Why you need it
Migrations keep your database structure versioned and in sync with your code.
Alternatives: `prisma db push` for quick prototyping without migration history.
Query your data
npx prisma studioWhat it does
Use the generated client in code, and Prisma Studio to browse data visually.
Why you need it
Type-safe queries catch mistakes at compile time and autocomplete your fields.