# Prisma ORM (Prisma ORM v7) (/docs/v7/prisma-postgres/quickstart/prisma-orm) > For the complete Prisma documentation index, see [llms.txt](https://www.prisma.io/docs/llms.txt). A markdown version of any docs page is available by appending `.md` to its URL. Create a new TypeScript project from scratch by connecting Prisma ORM to Prisma Postgres and generating a Prisma Client for database access Location: v7 > Prisma Postgres > Quickstart > Prisma ORM [Prisma Postgres](https://www.prisma.io/docs/postgres) is a managed PostgreSQL database that scales to zero and works with Prisma ORM and Prisma Studio. In this guide, you will learn how to set up a new TypeScript project from scratch, connect it to Prisma Postgres using Prisma ORM, and generate a Prisma Client for type-safe access to your database. ## Prerequisites [#prerequisites] ## 1. Create a new project [#1-create-a-new-project] ## 2. Install required dependencies [#2-install-required-dependencies] Install the packages needed for this quickstart: #### bun ```bash bun add prisma@prev @types/node --dev bun add @prisma/client@7 @prisma/adapter-pg dotenv ``` #### pnpm ```bash pnpm add prisma@prev @types/node --save-dev pnpm add @prisma/client@7 @prisma/adapter-pg dotenv ``` #### yarn ```bash yarn add prisma@prev @types/node --dev yarn add @prisma/client@7 @prisma/adapter-pg dotenv ``` #### npm ```bash npm install prisma@prev @types/node --save-dev npm install @prisma/client@7 @prisma/adapter-pg dotenv ``` Here's what each package does: * **`prisma`** - The Prisma CLI for running commands like `prisma init`, `prisma migrate`, and `prisma generate` * **`@prisma/client`** - The Prisma Client library for querying your database * **`@prisma/adapter-pg`** - The [`node-postgres` driver adapter](https://www.prisma.io/docs/orm/v7/core-concepts/supported-databases/postgresql#using-driver-adapters) that connects Prisma Client to your database * **`dotenv`** - Loads environment variables from your `.env` file ## 3. Configure ESM support [#3-configure-esm-support] Update `tsconfig.json` for ESM compatibility: ```json title="tsconfig.json" { "compilerOptions": { "module": "ESNext", "moduleResolution": "bundler", "target": "ES2023", "strict": true, "esModuleInterop": true, "ignoreDeprecations": "6.0" } } ``` Update `package.json` to enable ESM: ```json title="package.json" { "type": "module" // [!code ++] } ``` ## 4. Initialize Prisma ORM [#4-initialize-prisma-orm] Next, set up your Prisma ORM project by creating your [Prisma Schema](https://www.prisma.io/docs/orm/v7/prisma-schema/overview) file with the following command: #### bun ```bash bunx --bun prisma init --output ../generated/prisma ``` #### pnpm ```bash pnpm prisma init --output ../generated/prisma ``` #### yarn ```bash yarn prisma init --output ../generated/prisma ``` #### npm ```bash npx prisma init --output ../generated/prisma ``` > [!NOTE] > `prisma init` creates the Prisma scaffolding and a local `DATABASE_URL`. In the next step, replace that value with a direct `postgres://...` connection string from Prisma Postgres. This command does a few things: * Creates a `prisma/` directory with a `schema.prisma` file containing your database connection and schema models * Creates a `.env` file in the root directory for environment variables * Generates the Prisma Client in the `generated/prisma/` directory * Creates a `prisma7.config.ts` file for Prisma configuration The generated `prisma7.config.ts` file looks like this: ```typescript title="prisma7.config.ts" // This file was generated by Prisma, and assumes you have installed the following: // npm install --save-dev prisma dotenv import "dotenv/config"; import { defineConfig } from "prisma/config"; export default defineConfig({ schema: "prisma/schema.prisma", migrations: { path: "prisma/migrations", }, datasource: { url: process.env["DATABASE_URL"], }, }); ``` > [!NOTE] > Prisma ORM 7.10 and later name this file `prisma7.config.ts` so that it does not clash with the Prisma 8 config format, which only accepts `prisma.config.ts`. The Prisma 7 CLI discovers either name, so a project that already has a `prisma.config.ts` keeps working. The generated schema uses [the ESM-first `prisma-client` generator](https://www.prisma.io/docs/orm/v7/prisma-schema/overview/generators#prisma-client) with a custom output path: ```prisma title="prisma/schema.prisma" generator client { provider = "prisma-client" output = "../generated/prisma" } datasource db { provider = "postgresql" } ``` Create a Prisma Postgres database and replace the generated `DATABASE_URL` in your `.env` file with the `postgres://...` connection string from the CLI output: #### bun ```bash bunx create-db ``` #### pnpm ```bash pnpm dlx create-db ``` #### yarn ```bash yarn dlx create-db ``` #### npm ```bash npx create-db ``` ## 5. Define your data model [#5-define-your-data-model] Open `prisma/schema.prisma` and add the following models: ```prisma title="prisma/schema.prisma" generator client { provider = "prisma-client" output = "../generated/prisma" } datasource db { provider = "postgresql" } model User { // [!code ++] id Int @id @default(autoincrement()) // [!code ++] email String @unique // [!code ++] name String? // [!code ++] posts Post[] // [!code ++] } // [!code ++] model Post { // [!code ++] id Int @id @default(autoincrement()) // [!code ++] title String // [!code ++] content String? // [!code ++] published Boolean @default(false) // [!code ++] author User @relation(fields: [authorId], references: [id]) // [!code ++] authorId Int // [!code ++] } // [!code ++] ``` ## 6. Create and apply your first migration [#6-create-and-apply-your-first-migration] Create your first migration to set up the database tables: #### bun ```bash bunx prisma migrate dev --name init ``` #### pnpm ```bash pnpm prisma migrate dev --name init ``` #### yarn ```bash yarn prisma migrate dev --name init ``` #### npm ```bash npx prisma migrate dev --name init ``` This command creates the database tables based on your schema. Now run the following command to generate the Prisma Client: #### bun ```bash bunx prisma generate ``` #### pnpm ```bash pnpm prisma generate ``` #### yarn ```bash yarn prisma generate ``` #### npm ```bash npx prisma generate ``` ## 7. Instantiate Prisma Client [#7-instantiate-prisma-client] Now that you have all the dependencies installed, you can instantiate Prisma Client. You need to pass an instance of the Prisma ORM driver adapter adapter to the `PrismaClient` constructor: ```typescript title="lib/prisma.ts" import "dotenv/config"; import { PrismaPg } from "@prisma/adapter-pg"; import { PrismaClient } from "../generated/prisma/client"; const connectionString = `${process.env.DATABASE_URL}`; const adapter = new PrismaPg({ connectionString }); const prisma = new PrismaClient({ adapter }); export { prisma }; ``` > [!NOTE] > If you need to query your database via HTTP from an edge runtime (Cloudflare Workers, Vercel Edge Functions, etc.), use the [Prisma Postgres serverless driver](https://www.prisma.io/docs/postgres/database/serverless-driver#use-with-prisma-orm). ## 8. Write your first query [#8-write-your-first-query] Create a `script.ts` file to test your setup: ```typescript title="script.ts" import { prisma } from "./lib/prisma"; async function main() { // Create a new user with a post const user = await prisma.user.create({ data: { name: "Alice", email: "alice@prisma.io", posts: { create: { title: "Hello World", content: "This is my first post!", published: true, }, }, }, include: { posts: true, }, }); console.log("Created user:", user); // Fetch all users with their posts const allUsers = await prisma.user.findMany({ include: { posts: true, }, }); console.log("All users:", JSON.stringify(allUsers, null, 2)); } main() .then(async () => { await prisma.$disconnect(); }) .catch(async (e) => { console.error(e); await prisma.$disconnect(); process.exit(1); }); ``` Run the script: #### bun ```bash bunx tsx script.ts ``` #### pnpm ```bash pnpm dlx tsx script.ts ``` #### yarn ```bash yarn dlx tsx script.ts ``` #### npm ```bash npx tsx script.ts ``` You should see the created user and all users printed to the console. ## 9. Explore your data with Prisma Studio [#9-explore-your-data-with-prisma-studio] ```shell npx prisma studio ``` ## Next steps [#next-steps] Prisma ORM is set up. These are the pages you are most likely to need next: * **Learn more about Prisma Client**: Explore the [Prisma Client API](https://www.prisma.io/docs/orm/v7/prisma-client/setup-and-configuration/introduction) for advanced querying, filtering, and relations * **Database migrations**: Learn about [Prisma Migrate](https://www.prisma.io/docs/orm/v7/prisma-migrate) for evolving your database schema * **Performance optimization**: Discover [query optimization techniques](https://www.prisma.io/docs/orm/v7/prisma-client/queries/advanced/query-optimization-performance) * **Build a full application**: Check out our [framework guides](https://www.prisma.io/docs/guides/v7) to integrate Prisma ORM with Next.js, Express, and more * **Join the community**: Connect with other developers on [Discord](https://pris.ly/discord) > [!NOTE] > Deploy to Compute > > To run this app in the cloud, deploy it to [Prisma Compute](https://www.prisma.io/docs/compute), which runs your app next to your Prisma Postgres database. Follow [Deploy your first app](https://www.prisma.io/docs/prisma-compute/deploy). ## More info [#more-info] * [Prisma Postgres documentation](https://www.prisma.io/docs/postgres) * [Prisma Config reference](https://www.prisma.io/docs/orm/v7/reference/prisma-config-reference) * [Database connection management](https://www.prisma.io/docs/orm/v7/prisma-client/setup-and-configuration/databases-connections)