Embedded Prisma Studio (with Next.js)
Embed Prisma Studio in a Next.js application with @prisma/studio-core so you can browse and edit your database from inside your app.
Prisma Studio can be embedded directly into your Next.js application using the @prisma/studio-core package. This guide walks you through the setup so you can manage your database from within your app instead of running Prisma Studio separately.
After completing the guide, you'll have a Next.js app with Prisma Studio embedded, allowing you to browse and edit your database directly from your application interface:
Embedding Prisma Studio can be useful in scenarios such as:
- Building a quick admin dashboard for editing data
- Supporting multi-tenant applications where each user has their own database
- Giving users a UI to view and edit their own data
- Node.js 20+
- Basic knowledge of React and Next.js
- A database (PostgreSQL, SQLite, or MySQL)
First, create a new Next.js project from the directory where you want to build your app:
bunx create-next-app@latest nextjs-studio-embedpnpm dlx create-next-app@latest nextjs-studio-embedyarn dlx create-next-app@latest nextjs-studio-embednpx create-next-app@latest nextjs-studio-embedYou will be prompted to answer a few questions about your project. Select all of the defaults.
Then, navigate to the project directory:
cd nextjs-studio-embed2. Setting up Prisma ORM and Prisma Postgres
Section titled “2. Setting up Prisma ORM and Prisma Postgres”Install the required Prisma packages:
bun add prisma@prev tsx @types/pg --dev
bun add @prisma/extension-accelerate @prisma/client@7 @prisma/adapter-pg dotenv pgpnpm add prisma@prev tsx @types/pg --save-dev
pnpm add @prisma/extension-accelerate @prisma/client@7 @prisma/adapter-pg dotenv pgyarn add prisma@prev tsx @types/pg --dev
yarn add @prisma/extension-accelerate @prisma/client@7 @prisma/adapter-pg dotenv pgnpm install prisma@prev tsx @types/pg --save-dev
npm install @prisma/extension-accelerate @prisma/client@7 @prisma/adapter-pg dotenv pgbun add prisma@prev tsx --dev
bun add @prisma/client@7 @prisma/adapter-sqlite dotenv better-sqlite3pnpm add prisma@prev tsx --save-dev
pnpm add @prisma/client@7 @prisma/adapter-sqlite dotenv better-sqlite3yarn add prisma@prev tsx --dev
yarn add @prisma/client@7 @prisma/adapter-sqlite dotenv better-sqlite3npm install prisma@prev tsx --save-dev
npm install @prisma/client@7 @prisma/adapter-sqlite dotenv better-sqlite3bun add prisma@prev tsx @types/mysql2 --dev
bun add @prisma/client@7 @prisma/adapter-mysql dotenv mysql2pnpm add prisma@prev tsx @types/mysql2 --save-dev
pnpm add @prisma/client@7 @prisma/adapter-mysql dotenv mysql2yarn add prisma@prev tsx @types/mysql2 --dev
yarn add @prisma/client@7 @prisma/adapter-mysql dotenv mysql2npm install prisma@prev tsx @types/mysql2 --save-dev
npm install @prisma/client@7 @prisma/adapter-mysql dotenv mysql22.2. Initialize Prisma with Prisma Postgres
Section titled “2.2. Initialize Prisma with Prisma Postgres”Initialize Prisma in your project:
bunx --bun prisma init --output ../app/generated/prismapnpm prisma init --output ../app/generated/prismayarn prisma init --output ../app/generated/prismanpx prisma init --output ../app/generated/prismabunx --bun prisma init --datasource-provider sqlite --output ../app/generated/prismapnpm prisma init --datasource-provider sqlite --output ../app/generated/prismayarn prisma init --datasource-provider sqlite --output ../app/generated/prismanpx prisma init --datasource-provider sqlite --output ../app/generated/prismabunx --bun prisma init --datasource-provider mysql --output ../app/generated/prismapnpm prisma init --datasource-provider mysql --output ../app/generated/prismayarn prisma init --datasource-provider mysql --output ../app/generated/prismanpx prisma init --datasource-provider mysql --output ../app/generated/prismaThe prisma init command creates:
- A
prisma/directory with yourschema.prismafile - A
prisma.config.tsfile for configuring Prisma - A
.envfile with yourDATABASE_URL - An output directory at
app/generated/prismafor the Prisma Client
If you're using Prisma Postgres, create a database and replace the generated DATABASE_URL in your .env file with the postgres://... connection string from the CLI output:
The prisma init command creates:
- A
prisma/directory with yourschema.prismafile - A
prisma.config.tsfile for configuring Prisma - A
.envfile with yourDATABASE_URL - An output directory at
app/generated/prismafor the Prisma Client
If you're using Prisma Postgres, create a database and replace the generated DATABASE_URL in your .env file with the postgres://... connection string from the CLI output:
bunx create-dbpnpm dlx create-dbyarn dlx create-dbnpx create-dbOpen prisma/schema.prisma and replace the content with:
generator client {
provider = "prisma-client"
output = "../app/generated/prisma"
}
datasource db {
provider = "postgresql" // this will change depending on the --datasource-provider flag used in the init command
}
model User {
id Int @id @default(autoincrement())
name String
email String @unique
posts Post[]
}
model Post {
id Int @id @default(autoincrement())
title String
content String?
published Boolean @default(false)
authorId Int
author User @relation(fields: [authorId], references: [id])
createdAt DateTime @default(now())
} To get access to the variables in the .env file, they can either be loaded by your runtime, or by using dotenv. Include an import for dotenv at the top of the prisma.config.ts
import "dotenv/config";
import { defineConfig, env } from "prisma/config";
export default defineConfig({
schema: "prisma/schema.prisma",
migrations: {
path: "prisma/migrations",
},
datasource: {
url: env("DATABASE_URL"),
},
});Generate the Prisma Client and apply the schema:
bunx prisma migrate dev --name initpnpm prisma migrate dev --name inityarn prisma migrate dev --name initnpx prisma migrate dev --name initbunx prisma generatepnpm prisma generateyarn prisma generatenpx prisma generateThis creates the tables in your Prisma Postgres database and generates the Prisma Client.
Create a seed file to add some sample data. Create a seed.ts file in the prisma folder and add the following code:
import { PrismaClient } from "../app/generated/prisma/client";
import { PrismaPg } from "@prisma/adapter-pg";
const adapter = new PrismaPg({
connectionString: process.env.DATABASE_URL!,
});
const prisma = new PrismaClient({
adapter,
});
async function main() {
// Create users
const user1 = await prisma.user.create({
data: {
name: "Alice Johnson",
email: "alice@example.com",
},
});
const user2 = await prisma.user.create({
data: {
name: "Bob Smith",
email: "bob@example.com",
},
});
// Create posts
await prisma.post.create({
data: {
title: "Getting Started with Next.js",
content: "Next.js is a powerful React framework...",
published: true,
authorId: user1.id,
},
});
await prisma.post.create({
data: {
title: "Database Management with Prisma",
content: "Prisma makes database management easy...",
published: false,
authorId: user2.id,
},
});
console.log("Database seeded successfully!");
}
main()
.catch((e) => {
console.error(e);
process.exit(1);
})
.finally(async () => {
await prisma.$disconnect();
});import { PrismaClient } from "../app/generated/prisma/client";
import { PrismaSQLite } from "@prisma/adapter-sqlite";
const adapter = new PrismaSQLite({
connectionString: process.env.DATABASE_URL!,
});
const prisma = new PrismaClient({
adapter,
});
async function main() {
// Create users
const user1 = await prisma.user.create({
data: {
name: "Alice Johnson",
email: "alice@example.com",
},
});
const user2 = await prisma.user.create({
data: {
name: "Bob Smith",
email: "bob@example.com",
},
});
// Create posts
await prisma.post.create({
data: {
title: "Getting Started with Next.js",
content: "Next.js is a powerful React framework...",
published: true,
authorId: user1.id,
},
});
await prisma.post.create({
data: {
title: "Database Management with Prisma",
content: "Prisma makes database management easy...",
published: false,
authorId: user2.id,
},
});
console.log("Database seeded successfully!");
}
main()
.catch((e) => {
console.error(e);
process.exit(1);
})
.finally(async () => {
await prisma.$disconnect();
});import { PrismaClient } from "../app/generated/prisma/client";
import { PrismaMySQL } from "@prisma/adapter-mysql";
const adapter = new PrismaMySQL({
connectionString: process.env.DATABASE_URL!,
});
const prisma = new PrismaClient({
adapter,
});
async function main() {
// Create users
const user1 = await prisma.user.create({
data: {
name: "Alice Johnson",
email: "alice@example.com",
},
});
const user2 = await prisma.user.create({
data: {
name: "Bob Smith",
email: "bob@example.com",
},
});
// Create posts
await prisma.post.create({
data: {
title: "Getting Started with Next.js",
content: "Next.js is a powerful React framework...",
published: true,
authorId: user1.id,
},
});
await prisma.post.create({
data: {
title: "Database Management with Prisma",
content: "Prisma makes database management easy...",
published: false,
authorId: user2.id,
},
});
console.log("Database seeded successfully!");
}
main()
.catch((e) => {
console.error(e);
process.exit(1);
})
.finally(async () => {
await prisma.$disconnect();
});Add a seed script to your prisma.config.ts:
import "dotenv/config";
import { defineConfig, env } from "prisma/config";
export default defineConfig({
schema: "prisma/schema.prisma",
migrations: {
path: "prisma/migrations",
seed: `tsx prisma/seed.ts`,
},
datasource: {
url: env("DIRECT_URL"),
},
});import "dotenv/config";
import { defineConfig, env } from "prisma/config";
export default defineConfig({
schema: "prisma/schema.prisma",
migrations: {
path: "prisma/migrations",
seed: `tsx prisma/seed.ts`,
},
datasource: {
url: env("DATABASE_URL"),
},
});import "dotenv/config";
import { defineConfig, env } from "prisma/config";
export default defineConfig({
schema: "prisma/schema.prisma",
migrations: {
path: "prisma/migrations",
seed: `tsx prisma/seed.ts`,
},
datasource: {
url: env("DATABASE_URL"),
},
});Run the seed script:
bunx prisma db seedpnpm prisma db seedyarn prisma db seednpx prisma db seed3. Setting up the embedded Prisma Studio in your app
Section titled “3. Setting up the embedded Prisma Studio in your app”Now that you have Prisma ORM and Prisma Postgres set up, you can embed Prisma Studio in your Next.js app.
3.1. Install the Prisma Studio Core package
Section titled “3.1. Install the Prisma Studio Core package”Install the @prisma/studio-core package that provides the embeddable components:
bun add @prisma/studio-corepnpm add @prisma/studio-coreyarn add @prisma/studio-corenpm install @prisma/studio-core```bash bun add @prisma/studio-core --force ```pnpm
```bash pnpm add @prisma/studio-core --force ```yarn
```bash yarn add @prisma/studio-core --force ```npm
```bash npm install @prisma/studio-core --force ```If you are using yarn, pnpm, or another package manager, use the equivalent flag for your tool.
The @prisma/studio-core provides Studio, a React component which renders Prisma Studio for your database. The Studio component accepts an executor which accesses a custom endpoint in your backend. The backend uses your API key to identify the correct Prisma Postgres instance and sends the SQL query to it.
The @prisma/studio-core provides Studio, a React component which renders Prisma Studio for your database. The Studio component accepts an executor which accesses a custom endpoint in your backend. The backend uses your API key to identify the correct Prisma Postgres instance and sends the SQL query to it.
Create a components folder and add a new file called StudioWrapper.tsx. This file will wrap the Studio component and provide a consistent layout:
"use client";
import "@prisma/studio-core/ui/index.css";
import { ReactNode } from "react";
interface StudioWrapperProps {
children: ReactNode;
}
export default function StudioWrapper({ children }: StudioWrapperProps) {
return (
<div className="min-h-screen bg-gray-50">
<header className="bg-white shadow-sm border-b">
<div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
<div className="flex justify-between items-center py-4">
<h1 className="text-2xl font-bold text-gray-900">Database Studio</h1>
<div className="text-sm text-gray-500">Powered by Prisma Studio</div>
</div>
</div>
</header>
<main className="max-w-7xl mx-auto">
<div className="h-[calc(100vh-80px)]">{children}</div>
</main>
</div>
);
}3.3. Create an API endpoint to send the SQL queries to Prisma Studio
Section titled “3.3. Create an API endpoint to send the SQL queries to Prisma Studio”Next, set up a backend endpoint that Prisma Studio can communicate with. This endpoint receives SQL queries from the embedded Studio UI, forwards them to your Prisma Postgres database, and then returns the results (or errors) back to the frontend.
To do this, create a new folder called api inside the app directory. Inside it, add a studio folder with a route.ts file. This file will handle all requests sent to /api/studio and act as the bridge between the Studio component in your frontend and the database in your backend:
import "dotenv/config";
import { createPrismaPostgresHttpClient } from "@prisma/studio-core/data/ppg";
import { serializeError } from "@prisma/studio-core/data/bff";
const CORS_HEADERS = {
"Access-Control-Allow-Origin": "*", // Change to your domain in production
"Access-Control-Allow-Methods": "GET, POST, OPTIONS",
"Access-Control-Allow-Headers": "Content-Type, Authorization",
};
// Use dynamic rendering for database operations
export const dynamic = "force-dynamic";
export async function GET() {
return Response.json({ message: "Studio API endpoint is running" }, { headers: CORS_HEADERS });
}
export async function POST(request: Request) {
try {
const body = await request.json();
const query = body.query;
if (!query) {
return Response.json([serializeError(new Error("Query is required"))], {
status: 400,
headers: CORS_HEADERS,
});
}
const url = process.env.DATABASE_URL;
if (!url) {
const message = "❌ Environment variable DATABASE_URL is missing.";
return Response.json([serializeError(new Error(message))], {
status: 500,
headers: CORS_HEADERS,
});
}
const [error, results] = await createPrismaPostgresHttpClient({
url,
}).execute(query);
if (error) {
return Response.json([serializeError(error)], {
headers: CORS_HEADERS,
});
}
return Response.json([null, results], { headers: CORS_HEADERS });
} catch (err) {
return Response.json([serializeError(err)], {
status: 400,
headers: CORS_HEADERS,
});
}
}
// Handle preflight requests for CORS
export async function OPTIONS() {
return new Response(null, { status: 204, headers: CORS_HEADERS });
}import "dotenv/config";
import { createNodeSQLiteExecutor } from "@prisma/studio-core/data/node-sqlite";
import { serializeError } from "@prisma/studio-core/data/bff";
import DatabaseSync from "better-sqlite3";
const CORS_HEADERS = {
"Access-Control-Allow-Origin": "*", // Change to your domain in production
"Access-Control-Allow-Methods": "GET, POST, OPTIONS",
"Access-Control-Allow-Headers": "Content-Type, Authorization",
};
// Use dynamic rendering for database operations
export const dynamic = "force-dynamic";
export async function GET() {
return Response.json({ message: "Studio API endpoint is running" }, { headers: CORS_HEADERS });
}
export async function POST(request: Request) {
try {
const body = await request.json();
const query = body.query;
if (!query) {
return Response.json([serializeError(new Error("Query is required"))], {
status: 400,
headers: CORS_HEADERS,
});
}
const url = process.env.DATABASE_URL;
if (!url) {
const message = "❌ Environment variable DATABASE_URL is missing.";
return Response.json([serializeError(new Error(message))], {
status: 500,
headers: CORS_HEADERS,
});
}
const dbPath = url.replace("file:", "");
const database = new DatabaseSync(dbPath);
const [error, results] = await createNodeSQLiteExecutor(database).execute(query);
if (error) {
return Response.json([serializeError(error)], {
headers: CORS_HEADERS,
});
}
return Response.json([null, results], { headers: CORS_HEADERS });
} catch (err) {
return Response.json([serializeError(err)], {
status: 400,
headers: CORS_HEADERS,
});
}
}
// Handle preflight requests for CORS
export async function OPTIONS() {
return new Response(null, { status: 204, headers: CORS_HEADERS });
}import "dotenv/config";
import { createMySQL2Executor } from "@prisma/studio-core/data/mysql2";
import { serializeError } from "@prisma/studio-core/data/bff";
import mysql from "mysql2/promise";
const CORS_HEADERS = {
"Access-Control-Allow-Origin": "*", // Change to your domain in production
"Access-Control-Allow-Methods": "GET, POST, OPTIONS",
"Access-Control-Allow-Headers": "Content-Type, Authorization",
};
// Use dynamic rendering for database operations
export const dynamic = "force-dynamic";
export async function GET() {
return Response.json({ message: "Studio API endpoint is running" }, { headers: CORS_HEADERS });
}
export async function POST(request: Request) {
try {
const body = await request.json();
const query = body.query;
if (!query) {
return Response.json([serializeError(new Error("Query is required"))], {
status: 400,
headers: CORS_HEADERS,
});
}
const url = process.env.DATABASE_URL;
if (!url) {
const message = "❌ Environment variable DATABASE_URL is missing.";
return Response.json([serializeError(new Error(message))], {
status: 500,
headers: CORS_HEADERS,
});
}
const pool = mysql.createPool(url);
const [error, results] = await createMySQL2Executor(pool).execute(query);
if (error) {
return Response.json([serializeError(error)], {
headers: CORS_HEADERS,
});
}
return Response.json([null, results], { headers: CORS_HEADERS });
} catch (err) {
return Response.json([serializeError(err)], {
status: 400,
headers: CORS_HEADERS,
});
}
}
// Handle preflight requests for CORS
export async function OPTIONS() {
return new Response(null, { status: 204, headers: CORS_HEADERS });
}Open the app/page.tsx file and replace the existing code to render the embedded Studio with the following:
"use client";
import dynamic from "next/dynamic";
import { createPostgresAdapter } from "@prisma/studio-core/data/postgres-core";
import { createStudioBFFClient } from "@prisma/studio-core/data/bff";
import { useMemo, Suspense } from "react";
import StudioWrapper from "@/components/StudioWrapper";
// Dynamically import Studio with no SSR to avoid hydration issues
const Studio = dynamic(() => import("@prisma/studio-core/ui").then((mod) => mod.Studio), {
ssr: false,
});
// Loading component
const StudioLoading = () => (
<div className="flex items-center justify-center h-full">
<div className="text-center">
<div className="animate-spin rounded-full h-12 w-12 border-b-2 border-blue-600 mx-auto"></div>
<p className="mt-4 text-gray-600">Loading Studio...</p>
</div>
</div>
);
// Client-only Studio component
const ClientOnlyStudio = () => {
const adapter = useMemo(() => {
// Create the HTTP client that communicates with our API endpoint
const executor = createStudioBFFClient({
url: "/api/studio",
});
// Create the Postgres adapter using the executor
return createPostgresAdapter({ executor });
}, []);
return <Studio adapter={adapter} />;
};
export default function App() {
return (
<StudioWrapper>
<Suspense fallback={<StudioLoading />}>
<ClientOnlyStudio />
</Suspense>
</StudioWrapper>
);
}"use client";
import dynamic from "next/dynamic";
import { createSQLiteAdapter } from "@prisma/studio-core/data/sqlite-core";
import { createStudioBFFClient } from "@prisma/studio-core/data/bff";
import { useMemo, Suspense } from "react";
import StudioWrapper from "@/components/StudioWrapper";
// Dynamically import Studio with no SSR to avoid hydration issues
const Studio = dynamic(() => import("@prisma/studio-core/ui").then((mod) => mod.Studio), {
ssr: false,
});
// Loading component
const StudioLoading = () => (
<div className="flex items-center justify-center h-full">
<div className="text-center">
<div className="animate-spin rounded-full h-12 w-12 border-b-2 border-blue-600 mx-auto"></div>
<p className="mt-4 text-gray-600">Loading Studio...</p>
</div>
</div>
);
// Client-only Studio component
const ClientOnlyStudio = () => {
const adapter = useMemo(() => {
// Create the HTTP client that communicates with our API endpoint
const executor = createStudioBFFClient({
url: "/api/studio",
});
// Create the SQLite adapter using the executor
return createSQLiteAdapter({ executor });
}, []);
return <Studio adapter={adapter} />;
};
export default function App() {
return (
<StudioWrapper>
<Suspense fallback={<StudioLoading />}>
<ClientOnlyStudio />
</Suspense>
</StudioWrapper>
);
}"use client";
import dynamic from "next/dynamic";
import { createMySQLAdapter } from "@prisma/studio-core/data/mysql-core";
import { createStudioBFFClient } from "@prisma/studio-core/data/bff";
import { useMemo, Suspense } from "react";
import StudioWrapper from "@/components/StudioWrapper";
// Dynamically import Studio with no SSR to avoid hydration issues
const Studio = dynamic(() => import("@prisma/studio-core/ui").then((mod) => mod.Studio), {
ssr: false,
});
// Loading component
const StudioLoading = () => (
<div className="flex items-center justify-center h-full">
<div className="text-center">
<div className="animate-spin rounded-full h-12 w-12 border-b-2 border-blue-600 mx-auto"></div>
<p className="mt-4 text-gray-600">Loading Studio...</p>
</div>
</div>
);
// Client-only Studio component
const ClientOnlyStudio = () => {
const adapter = useMemo(() => {
// Create the HTTP client that communicates with our API endpoint
const executor = createStudioBFFClient({
url: "/api/studio",
});
// Create the MySQL adapter using the executor
return createMySQLAdapter({ executor });
}, []);
return <Studio adapter={adapter} />;
};
export default function App() {
return (
<StudioWrapper>
<Suspense fallback={<StudioLoading />}>
<ClientOnlyStudio />
</Suspense>
</StudioWrapper>
);
}3.5. Start your development server and test the embedded Studio
Section titled “3.5. Start your development server and test the embedded Studio”Start your Next.js development server:
bun run devOpen your browser and go to http://localhost:3000. You should now see Prisma Studio running inside your application:
Here's what to look for:
-
Prisma Studio interface: The full Prisma Studio UI should render within your app layout.
-
Your data: The
UserandPosttables you defined (plus any seeded data) should appear. -
Interactive features:
- Browse and filter records in your tables
- Edit values inline by double-clicking cells
- Add new records using the "Add record" button
- Delete records you no longer need
- Explore relationships by navigating between related tables
Verify whether everything works by testing the basics:
- Click on different tables to confirm your data loads.
- Update a record to check that changes are saved.
- Add a new record and confirm it appears instantly.
- Try filtering data to make sure queries run correctly.
- Navigate through relationships (for example, view a user's posts) to confirm associations work.
Once these actions work as expected, your embedded Prisma Studio is set up and connected to your database.
At this point you have Prisma Studio running inside your Next.js application and connected to your database. You can browse, edit, and manage your data without leaving your app. To make this setup production-ready, consider these improvements:
- Add authentication: Currently, anyone who can open your app has access to Prisma Studio. Add user authentication and only allow specific roles (for example, admins) to use the embedded Studio. You can do this by checking authentication tokens in your
/api/studioendpoint before running queries. - Use environment-specific configuration: In development you may want a test database, while in production you'll need a separate live database. Update your
.envfile to use differentDATABASE_URLvalues for each environment, and confirm that your/api/studioendpoint is reading the correct one. - Apply custom styling: The Studio component ships with a default look. Pass in your own theme and adjust colors, typography, or branding to match the rest of your application. This helps Studio feel like a native part of your app rather than a standalone tool.
By adding authentication, environment-specific settings, and styling, you move from a working demo to a production setup.
For more patterns and examples, see the Prisma Studio Core demo repository, which includes an alternative implementation using Hono.js and React. If you prefer a guided walkthrough, watch the YouTube video: **Use Prisma Studio in Your Own Applications **.