Prisma Support for Edge Functions - env var

Hi,

I’m trying to get Prisma Data Proxy to work on the edge functions and there is 1 missing piece, which is access to the environment variables in the schema.prisma file.

A prisma schema reads its database url from the environment as follows:

datasource db {
  url      = env("DATABASE_URL")
}

This environment variable is set both in a .env and in the env variables in the site’s settings, but when running you get:

◈ Failed to run Edge Function server:
InvalidDatasourceError: Datasource "db" references an environment variable "DATABASE_URL" that is not set

This is because apparently you need to read the env variables with Deno.env.get() (Edge Functions API | Netlify Docs), but such call is not supported by Prisma (only strings and the env() function is allowed).

When I set the database string directly in the datasource, everything works.

I think supporting Prisma for the edge functions is a big traction feature, is there any way I can already solve this?

Thanks.

Hey @ticup , thanks for the feedback! I’ll submit this as a feature request to our product team so they can take it into consideration for new improvements to our service. Let us know if you have any other questions!

For those stumbling upon this post. There is a workaround for this by getting the database string from the environment in the PrismaClient constructor, from Prisma edge client can't read env vars · Issue #18542 · prisma/prisma · GitHub :

import { DATABASE_URL } from "$env/static/private";

  new PrismaClient({
    datasources: {
      db: {
        url: DATABASE_URL
      }
    }
  });
1 Like

Thank you for providing this information for future users!