StackKit LogoStackKit
ModulesDatabase

Prisma

A modern, type-safe ORM for PostgreSQL, MySQL, SQLite, and MongoDB. Prisma gives you auto-generated types and a clean query API.

Prisma is a TypeScript-first ORM that turns your database schema into fully-typed query methods. StackKit sets it up with the right configuration for your chosen database provider.

Compatible frameworks

Prisma is currently available for Express projects.

Installation

In a new project

Choose your database provider with the --database flag:

npx stackkit@latest create my-app --database prisma-postgresql
npx stackkit@latest create my-app --database prisma-mysql
npx stackkit@latest create my-app --database prisma-sqlite
npx stackkit@latest create my-app --database prisma-mongodb

In an existing project

npx stackkit@latest add
# Navigate to: Database → Prisma → (select your provider)

What gets generated

  • prisma/schema.prisma — Your database schema. The provider is pre-configured for your chosen database.
  • src/lib/db.ts — A singleton Prisma Client instance ready to import anywhere in your app.
  • .env.example — A DATABASE_URL entry with the correct format for your provider.

Setup

Copy your environment file

cp .env.example .env

Set your database URL

Open .env and update DATABASE_URL with your actual connection details:

DATABASE_URL="postgresql://user:password@localhost:5432/mydb"
DATABASE_URL="mysql://user:password@localhost:3306/mydb"
DATABASE_URL="file:./dev.db"

SQLite stores data in a local file. No database server needed.

DATABASE_URL="mongodb://localhost:27017/mydb"
# MongoDB Atlas:
DATABASE_URL="mongodb+srv://user:[email protected]/mydb"

Run your first migration

For PostgreSQL, MySQL, and SQLite, create and apply the initial migration:

npx prisma migrate dev --name init

For MongoDB, push your schema directly (Prisma doesn't use migrations with MongoDB):

npx prisma db push

Generate Prisma Client

This step is automatic after migrations, but you can run it manually if needed:

npx prisma generate

Common commands

npx prisma migrate dev              # Create and apply a new migration
npx prisma migrate dev --name init  # Create with a specific name
npx prisma generate                 # Regenerate the Prisma Client
npx prisma studio                   # Open the visual database browser
npx prisma db push                  # Sync schema without creating a migration
npx prisma db seed                  # Run your seed script

Using the Prisma Client

The generated src/lib/db.ts file exports a singleton Prisma Client instance. Import it wherever you need to query the database:

import { db } from "@/lib/db";

// Fetch all users
const users = await db.user.findMany();

// Create a new user
const user = await db.user.create({
  data: {
    name: "Alice",
    email: "[email protected]",
  },
});

The Prisma Client types are generated from your schema, so you get full autocomplete and type checking for every query.

Next steps

On this page