question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cloudflare Workers with PlanetScale db

See original GitHub issue

I want to use prisma with Cloudflare workers and PlanetScale db using JS and not TS.

I have created the webpack config

module.exports = {
  entry: './src/index.js',
  target: 'webworker',
  resolve: {
    extensions: ['.ts', '.tsx', '.js', '.jsx'],
    // Alias for resolving the Prisma Client properly
    alias: {
      '@prisma/client$': require.resolve('@prisma/client'),
    },
  },
  devtool: 'none',
}

and schema

generator client {
  provider = "prisma-client-js"
  previewFeatures = ["referentialIntegrity", "dataProxy"]
}

datasource db {
  provider = "mysql"
  url      = env("DATABASE_URL")
  referentialIntegrity = "prisma"
}

model Test {
  id            Int      @id @default(autoincrement())
  name          String
  city          String
  www           String

Now it all trows pleny of errors. When I try to use db push I get:

% npx prisma db push           
Environment variables loaded from .env
Prisma schema loaded from prisma/schema.prisma
Error: Get config: Schema Parsing P1012

error: Error validating datasource `db`: the URL must start with the protocol `mysql://`.
  -->  schema.prisma:11
   | 
10 |   provider = "mysql"
11 |   url      = env("DATABASE_URL")
   | 

Validation Error Count: 1

Next while using wrangler dev I have a ton of lines mostly around missing modules.

What is more there is a missing step of using npx prisma db push.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
millspcommented, Jun 7, 2022

Hey @konradbjk, hey everyone. We have released some changes a few minutes ago in prisma@3.15.0. tl;dr;

  • Instead of PRISMA_CLIENT_ENGINE_TYPE, use prisma generate --data-proxy to enable the Data Proxy
  • import { PrismaClient } from '@prisma/client/edge' for a Workers-compatible Prisma Client
  • Please be aware that .env aren’t bundled into the generated Prisma Client any longer (see docs)
  • You can also remove any package location aliasing from your build scripts
  • Warnings around eval are now also fixed

Thanks everyone, and your feedback is welcome.

1reaction
SebJansencommented, May 25, 2022

the URL must start with the protocol mysql://, I think it could be due to either of two reasons:

  • Prisma client hasn’t been generated with dataproxy, do PRISMA_CLIENT_ENGINE_TYPE=dataproxy npx prisma generate. A mysql://... connection string only works for non-dataproxy projects, and Cloudflare Workers needs the dataproxy because Workers can only connect through HTTP which requires a connection string resembling prisma://....
  • You have a space in your DATABASE_URL env var, it has happened often to me.
Read more comments on GitHub >

github_iconTop Results From Across the Web

Introducing the PlanetScale serverless driver for JavaScript
The ability to store and query data in PlanetScale from environments such as Cloudflare Workers, Vercel Edge Functions, and Netlify Edge ...
Read more >
Databases · Cloudflare Workers docs
Use Cloudflare Workers to connect your application to external databases, such as Postgres, MySQL, FaunaDB, Supabase, MongoDB Atlas, ...
Read more >
PlanetScale reaches to the edge with serverless driver
The driver creates a new layer to the PlanetScale database that enables ... Edge services, including Cloudflare Workers, have provided users ...
Read more >
The PlanetScale serverless driver for JavaScript | Hacker News
Think Cloudflare Workers, Vercel Edge Functions, AWS Lambda, etc. ... Unlike many DB providers, PlanetScale supports nearly unlimited connections.
Read more >
PlanetScale on Twitter: "Where do you deploy your serverless ...
If I am not using Vercel (so it isn't NextJS) it is likely a Cloudflare Worker. If for whatever reason I need to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found