To use the Data Proxy for a JavaScript/TypeScript application that uses Prisma, you must first create a project in Prisma Data Platform. When you create the project, you do the following:

Note

When you create your project, you do not need to also create a Data Proxy connection string. You can always create a new Data Proxy connection string at a later time as described below in Enable Data Proxy for a project.

You can then configure the connection string in your development or deployment environment and generate Prisma Client for the Data Proxy.

Enable the Data Proxy for a project

When you create a project in the platform, the Data Proxy is automatically enabled for your project.

Note

The fact that the Data Proxy is enabled for a project does not yet mean that your application starts to use the proxy.

Your application starts to use the proxy only after you configure a generated Data Proxy connection string as an environment variable for your project so that Prisma Client uses the proxy connection string and not the direct connection to the database.

Prerequisites

  • Create a project to add your application in the platform. During the process, select a geographic location for the Data Proxy that is closest to the location of your database.
  • If your database is behind a firewall, enable static IP addresses for your project and add the IP addresses for the selected Data Proxy region to the allowlist of your database.
    • US East 1 (West Virginia)
      • 54.204.197.119
      • 3.222.148.224
      • 54.204.47.202
      • 3.227.136.248
    • EU Central 1 (Frankfurt, Germany)
      • 35.157.74.165
      • 18.194.25.248
      • 18.184.112.103
      • 18.157.219.25

Steps

  1. Open your project in the Prisma Data Platform. You can do so from the Projects page.

  2. Get a Data Proxy connection string for the selected environment.

    1. With the project open and an environment selected, click the Data Proxy tab.

    2. Click Create a connection string.

      Note

      You can generate as many Data Proxy connection strings as you need. You can later revoke any of the connection strings that you no longer need.
    3. Enter a name for the new Data Proxy connection string and click Create.

      Prisma Data Platform - Data Proxy - Create and name a new Data Proxy connection string
    4. Copy the prisma:// connection string.

      Important

      Save the prisma:// connection string securely. After you navigate to another page, you cannot retrieve the connection string again from the Data Proxy. You can only generate a new connection string, if necessary.
      Prisma Data Platform - Data Proxy - Copy the Data Proxy connection string

Generate Prisma Client for the Data Proxy

After you create your project in the platform and enable the Data Proxy, you can generate Prisma Client for the Data Proxy and use it with the prisma:// connection string you obtained.

You can generate and use Prisma Client for the Data Proxy in the following environments:

  • In your local development environment, to test the process.
  • In your deployment platform. You must replace the direct database connection string with the Data Proxy connection string and make sure that Prisma Client is auto-generated with the --data-proxy flag as described below.

Prerequisites

Steps

  1. In your local development environment, replace the direct database connection string with the Data Proxy prisma:// connection string.

    .env
    - DATABASE_URL="postgresql://****:****@****"
    + DATABASE_URL="prisma://****:****@****"

    Note

    For security reasons, we strongly recommend that you always use environment variables for your database connection strings and Data Proxy strings. Do not hard-code them into your schema.prisma file.

    For more information, see Using .env files.

  2. Install prisma and @prisma/client.

    Make sure to use version 3.15.2 or later.

    $npm install prisma@latest --save-dev
    $npm install @prisma/client@latest --save
  3. Generate Prisma Client with the --data-proxy option.

    $npx prisma generate --data-proxy

    The generated Prisma Client is a lightweight version because it excludes the local query engine files. The Data Proxy handles the query engine logic.

  4. Instantiate Prisma Client in your application code.

    • To use the Data Proxy with Node.js, instantiate @prisma/client. Learn more.

      TypeScript
      JavaScript
      import { PrismaClient } from '@prisma/client'
      const prisma = new PrismaClient()
      // use `prisma` in your application to read and write data in your DB
    • To use the Data Proxy in Edge runtimes, such as Cloudflare Workers or Vercel Edge Functions, instantiate @prisma/client/edge.

      Note

      You can use @prisma/client/edge only with the Data Proxy. In such cases, make sure to use the --data-proxy flag or the PRISMA_GENERATE_DATAPROXY=true environment variable when you generate Prisma Client.
      TypeScript
      JavaScript
      import { PrismaClient } from '@prisma/client/edge'
      const prisma = new PrismaClient()
      // use `prisma` in your application to read and write data in your DB

Result

Your application now uses the Data Proxy.

The generated Prisma Client has a reduced bundle size because the entire query engine logic is now hosted with the Data Proxy.

Manage the number of database connections

You can adjust the maximum number of database connections of each Data Proxy connection pool.

To do so, in the Prisma Data Platform add the connection_limit parameter to the database connection string of the environment in your project.

postgresql://user:password@host:5432/mydb?connection_limit=60
Edit this page on GitHub