Prisma Quickstart

prisma/prisma

A Clarity
6 Steps
10 min Time
macOS, Linux, Windows Tested On
100% Copy-Paste Ready
0 Issues

Get Prisma ORM running with TypeScript and query your first database in under 10 minutes. This guide covers project setup, schema definition, migrations, and basic CRUD operations using SQLite.

Prerequisites

  • 📦
    Node.js Version 18.0 or higher
  • 💻
    Terminal Command line access (bash, zsh, PowerShell)
  • 📝
    Code Editor VS Code recommended for Prisma extension support

Initialize Project

1

Initialize Project

~2 min

Create a new directory and initialize a TypeScript project with Prisma:

bash
mkdir prisma-quickstart
cd prisma-quickstart
npm init -y
npm install prisma typescript ts-node @types/node --save-dev
npm install @prisma/client

Initialize TypeScript configuration:

bash
npx tsc --init

Initialize Prisma with SQLite:

bash
npx prisma init --datasource-provider sqlite
Expected output:
✔ Your Prisma schema was created at prisma/schema.prisma
  You can now open it in your favorite editor.

Next steps:

  1. Set the DATABASE_URL in the .env file to point to your existing database.
  2. Run prisma db pull to turn your database schema into a Prisma schema.
  3. Run prisma generate to generate the Prisma Client.

💡 This creates a prisma folder with schema.prisma and a .env file for your database URL.

Set Up Database Connection

2

Set Up Database Connection

~1 min

SQLite is already configured. Verify your .env file contains:

env
DATABASE_URL="file:./dev.db"

Your prisma/schema.prisma should look like this:

prisma
generator client {
  provider = "prisma-client-js"
}

datasource db { provider = “sqlite” url = env(“DATABASE_URL”) }

📝 SQLite stores data in a local file, perfect for development. For production, switch to PostgreSQL or MySQL.

Define Your Schema

3

Define Your Schema

~2 min

Add a User and Post model to your prisma/schema.prisma:

prisma
generator client {
  provider = "prisma-client-js"
}

datasource db { provider = “sqlite” url = env(“DATABASE_URL”) }

model User { id Int @id @default(autoincrement()) email String @unique name String? posts Post[] createdAt DateTime @default(now()) }

model Post { id Int @id @default(autoincrement()) title String content String? published Boolean @default(false) author User @relation(fields: [authorId], references: [id]) authorId Int createdAt DateTime @default(now()) }

💡 The @relation directive creates a foreign key relationship. Each Post belongs to one User, and each User can have many Posts.

Run Migrations

4

Run Migrations

~1 min

Create and apply your first migration:

bash
npx prisma migrate dev --name init
Expected output:
Environment variables loaded from .env
Prisma schema loaded from prisma/schema.prisma
Datasource "db": SQLite database "dev.db" at "file:./dev.db"

SQLite database dev.db created at file:./dev.db

Applying migration 20260203120000_init

The following migration(s) have been created and applied from new schema changes:

migrations/ └─ 20260203120000_init/ └─ migration.sql

Your database is now in sync with your schema.

✔ Generated Prisma Client (v5.x.x) to ./node_modules/@prisma/client

🎉
Database created!

Your SQLite database is ready with User and Post tables.

Add Data with Prisma Client

5

Add Data with Prisma Client

~2 min

Create a script to add data. Save this as script.ts:

typescript
import { PrismaClient } from '@prisma/client'

const prisma = new PrismaClient()

async function main() { // Create a user with a post const user = await prisma.user.create({ data: { email: ‘[email protected]’, name: ‘Alice’, posts: { create: { title: ‘Hello Prisma’, content: ‘This is my first post!’, published: true, }, }, }, include: { posts: true, }, })

console.log(‘Created user with post:’, user)

// Create another user const bob = await prisma.user.create({ data: { email: ‘[email protected]’, name: ‘Bob’, }, })

console.log(‘Created user:’, bob) }

main() .catch((e) => { console.error(e) process.exit(1) }) .finally(async () => { await prisma.$disconnect() })

Run the script:

bash
npx ts-node script.ts
Expected output:
Created user with post: {
  id: 1,
  email: '[email protected]',
  name: 'Alice',
  createdAt: 2026-02-03T12:00:00.000Z,
  posts: [
    {
      id: 1,
      title: 'Hello Prisma',
      content: 'This is my first post!',
      published: true,
      authorId: 1,
      createdAt: 2026-02-03T12:00:00.000Z
    }
  ]
}
Created user: { id: 2, email: '[email protected]', name: 'Bob', createdAt: 2026-02-03T12:00:00.000Z }

💡 The include option tells Prisma to return related posts along with the user.

Query Data

6

Query Data

~2 min

Create a new file query.ts to explore different queries:

typescript
import { PrismaClient } from '@prisma/client'

const prisma = new PrismaClient()

async function main() { // Get all users const allUsers = await prisma.user.findMany({ include: { posts: true }, }) console.log(‘All users:’, JSON.stringify(allUsers, null, 2))

// Find a specific user by email const alice = await prisma.user.findUnique({ where: { email: ‘[email protected]’ }, }) console.log(’\nFound Alice:’, alice)

// Get all published posts const publishedPosts = await prisma.post.findMany({ where: { published: true }, include: { author: true }, }) console.log(’\nPublished posts:’, publishedPosts)

// Update a post const updatedPost = await prisma.post.update({ where: { id: 1 }, data: { title: ‘Hello Prisma (Updated)’ }, }) console.log(’\nUpdated post:’, updatedPost)

// Count users const userCount = await prisma.user.count() console.log(’\nTotal users:’, userCount) }

main() .catch((e) => { console.error(e) process.exit(1) }) .finally(async () => { await prisma.$disconnect() })

Run the query script:

bash
npx ts-node query.ts
Expected output:
All users: [
  {
    "id": 1,
    "email": "[email protected]",
    "name": "Alice",
    "createdAt": "2026-02-03T12:00:00.000Z",
    "posts": [
      {
        "id": 1,
        "title": "Hello Prisma",
        "content": "This is my first post!",
        "published": true,
        "authorId": 1,
        "createdAt": "2026-02-03T12:00:00.000Z"
      }
    ]
  },
  {
    "id": 2,
    "email": "[email protected]",
    "name": "Bob",
    "createdAt": "2026-02-03T12:00:00.000Z",
    "posts": []
  }
]

Found Alice: { id: 1, email: ‘[email protected]’, name: ‘Alice’, createdAt: 2026-02-03T12:00:00.000Z }

Published posts: [ { id: 1, title: ‘Hello Prisma’, content: ‘This is my first post!’, published: true, authorId: 1, createdAt: 2026-02-03T12:00:00.000Z, author: { id: 1, email: ‘[email protected]’, name: ‘Alice’, createdAt: 2026-02-03T12:00:00.000Z } } ]

Updated post: { id: 1, title: ‘Hello Prisma (Updated)’, content: ‘This is my first post!’, published: true, authorId: 1, createdAt: 2026-02-03T12:00:00.000Z }

Total users: 2

Explore your data visually with Prisma Studio:

bash
npx prisma studio
🔍 http://localhost:5555
🚀
You're now using Prisma!

You've set up a database, defined a schema, and performed CRUD operations with type-safe queries.

Next Steps