Quickstart
In this Quickstart guide, you'll learn how to get started from scratch with Prisma ORM and a Prisma Postgres database in a plain TypeScript project. It covers the following workflows:
- Creating a Prisma Postgres database
- Schema migrations and queries (via Prisma ORM)
- Connection pooling and caching (via Prisma Accelerate)
Prerequisites
To successfully complete this tutorial, you need:
- a (PDP) account
- Node.js installed on your machine (see system requirements for officially supported versions)
1. Set up a Prisma Postgres database in the Platform Console
Follow these steps to create your Prisma Postgres database:
- Log in to and open the Console.
- In a workspace of your choice, click the New project button.
- Type a name for your project in the Name field, e.g. hello-ppg.
- In the Prisma Postgres section, click the Get started button.
- In the Region dropdown, select the region that's closest to your current location, e.g. US East (N. Virginia).
- Click the Create project button.
At this point, you'll be redirected to the Database page where you will need to wait for a few seconds while the status of your database changes from PROVISIONING
to CONNECTED
.
Once the green CONNECTED
label appears, your database is ready to use!
2. Download example and install dependencies
Copy the try-prisma
command that's shown in the Console, paste it into your terminal and execute it.
For reference, this is what the command looks like:
npx try-prisma@latest \
--template databases/prisma-postgres \
--name hello-prisma \
--install npm
Once the try-prisma
command has terminated, navigate into the project directory:
cd hello-prisma
3. Set database connection URL
The connection to your database is configured via an environment variable in a .env
file.
First, rename the existing .env.example
file to just .env
:
mv .env.example .env
Then, in your project environment in the Platform console, find your database credentials in the Set up database access section, copy the DATABASE_URL
environment variable and paste them into the .env
file.
For reference, the file should now look similar to this:
DATABASE_URL="prisma+postgres://accelerate.prisma-data.net/?api_key=ey...."
4. Create database tables (with a schema migration)
Next, you need to create the tables in your database. You can do this by creating and executing a schema migration with the following command of the Prisma CLI:
npx prisma migrate dev --name init
This will map the User
and Post
models that are defined in your Prisma schema to your database. You can also review the SQL migration that was executed and created the tables in the newly created prisma/migrations
directory.
5. Execute queries with Prisma ORM
The src/queries.ts
script contains a number of CRUD queries that will write and read data in your database. You can execute it by running the following command in your terminal:
npm run queries
Once the script has completed, you can inspect the logs in your terminal or use Prisma Studio to explore what records have been created in the database:
npx prisma studio
6. Explore caching with Prisma Accelerate
The src/caching.ts
script contains a sample query that uses Stale-While-Revalidate (SWR) and Time-To-Live (TTL) to cache a database query using Prisma Accelerate. You can execute it as follows:
npm run caching
Take note of the time that it took to execute the query, e.g.:
The query took 2009.2467149999998ms.
Now, run the script again:
npm run caching
You'll notice that the time the query took will be a lot shorter this time, e.g.:
The query took 300.5655280000001ms.
7. Next steps
In this Quickstart guide, you have learned how to get started with Prisma ORM in a plain TypeScript project. Feel free to explore the Prisma Client API a bit more on your own, e.g. by including filtering, sorting, and pagination options in the findMany
query or exploring more operations like update
and delete
queries.
Explore the data in Prisma Studio
Prisma ORM comes with a built-in GUI to view and edit the data in your database. You can open it using the following command:
npx prisma studio
With Prisma Postgres, you can also directly use Prisma Studio inside the by selecting the Studio tab in your project.
Build a fullstack app with Next.js
Learn how to use Prisma Postgres in a fullstack app:
- Build a fullstack app with Next.js 15
- Next.js 15 example app (including authentication)
Explore ready-to-run Prisma ORM examples
Check out the prisma-examples
repository on GitHub to see how Prisma ORM can be used with your favorite library. The repo contains examples with Express, NestJS, GraphQL as well as fullstack examples with Next.js and Vue.js, and a lot more.
These examples use SQLite by default but you can follow the instructions in the project README to switch to Prisma Postgres in a few simple steps.
Stay connected with Prisma
Continue your Prisma journey by connecting with our active community. Stay informed, get involved, and collaborate with other developers:
- Follow us on X for announcements, live events and useful tips.
- Join our Discord to ask questions, talk to the community, and get active support through conversations.
- Subscribe on YouTube for tutorials, demos, and streams.
- Engage on GitHub by starring the repository, reporting issues, or contributing to an issue.