This project showcases how to use the Prisma ORM with Prisma Postgres in an ESM Deno Deploy application.
To successfully run the project, you will need the following:
- Two Prisma Postgres connection strings:
- Your Prisma Postgres + Accelerate connection string (containing your Prisma API key) which you can get by enabling Postgres in a project in your Prisma Data Platform account. You will use this connection string to run Prisma migrations.
- Your Prisma Postgres direct TCP connection string which you will use with Prisma Client. Learn more in the docs.
-
Deno 2
-
ESM
-
Prisma Client with the
prisma-clientgenerator See the Prisma schema file for details.generator client { provider = "prisma-client" output = "../src/generated/prisma" previewFeatures = ["driverAdapters", "queryCompiler"] runtime = "deno" }
Clone the repository, navigate into it and install dependencies:
git clone git@github.com:prisma/prisma-examples.git --depth=1
cd prisma-examples/generator-prisma-client/deno-deploy
deno install
Create a .env in the root of the project directory:
touch .envNow, open the .env file and set the DATABASE_URL environment variables with the values of your connection string and your Prisma Postgres connection string:
# .env
# Prisma Postgres connection string (used for migrations)
DATABASE_URL="__YOUR_PRISMA_POSTGRES_CONNECTION_STRING__"
# Postgres connection string (used for queries by Prisma Client)
DIRECT_URL="__YOUR_PRISMA_POSTGRES_DIRECT_CONNECTION_STRING__"Note that __YOUR_PRISMA_POSTGRES_CONNECTION_STRING__ is a placeholder value that you need to replace with the values of your Prisma Postgres + Accelerate connection string. Notice that the Accelerate connection string has the following structure: prisma+postgres://accelerate.prisma-data.net/?api_key=<api_key_value>.
Note that __YOUR_PRISMA_POSTGRES_DIRECT_CONNECTION_STRING__ is a placeholder value that you need to replace with the values of your Prisma Postgres direct TCP connection string. The direct connection string has the following structure: postgres://<username>:<password>@<host>:<port>/<database>.
The Prisma schema file contains a single Quotes model and a QuoteKind enum. You can map this model to the database and create the corresponding Quotes table using the following command:
deno task prisma migrate dev --name init
You now have an empty Quotes table in your database. Next, run the seed script to create some sample records in the table:
deno task prisma db seed
Run:
deno task prisma generate
You can run the app with the following command:
deno task dev
To deploy your application to Deno Deploy, follow these steps:
deno install -gArf jsr:@deno/deployctl
deployctl deploy --project=prisma-client-deno-deploy --env-file=.env
- Prisma Postgres documentation
- Check out the Prisma docs
- Join our community on Discord to share feedback and interact with other users.
- Subscribe to our YouTube channel for live demos and video tutorials.
- Follow us on X for the latest updates.
- Report issues or ask questions on GitHub.