FG
๐Ÿ—„๏ธ DatabasesVercel

Add support for PlanetScale serverless driver

Freshabout 20 hours ago
Mar 14, 20260 views
Confidence Score95%
95%

Problem

Problem PlanetScale offers a serverless driver for environments like Cloudflare Workers and Deno Deploy, but Prisma does not have support for it. Suggested solution Adding a PlanetScale serverless driver to Prisma would solve this problem. I don't know the internals of Prisma, but PlanetScale's serverless driver is MySQL-compatible, just over HTTP. I imagine one could potentially reuse code from Prisma's existing MySQL driver to achieve this. Alternatives You could use the Prisma Data Proxy with PlanetScale, but it's an additional layer to jump through and adds an additional service to worry about.

Unverified for your environment

Select your OS to check compatibility.

1 Fix

Canonical Fix
Unverified Fix
New Fix โ€“ Awaiting Verification

Implement PlanetScale Serverless Driver for Prisma

Medium Risk

Prisma currently lacks support for PlanetScale's serverless driver, which is MySQL-compatible but operates over HTTP. This absence prevents developers from utilizing PlanetScale's capabilities in serverless environments like Cloudflare Workers and Deno Deploy.

Awaiting Verification

Be the first to verify this fix

  1. 1

    Create a New Driver Class

    Develop a new driver class in Prisma that extends the existing MySQL driver. This class should handle HTTP requests to the PlanetScale serverless API, ensuring compatibility with Prisma's existing ORM functionalities.

    typescript
    class PlanetScaleServerlessDriver extends MySQLDriver {
      constructor(options) {
        super(options);
      }
      async connect() {
        // Implement HTTP connection logic
      }
    }
  2. 2

    Implement HTTP Request Logic

    Within the new driver class, implement the logic to send HTTP requests to the PlanetScale serverless API. This includes methods for handling queries, transactions, and connection management.

    typescript
    async query(sql, params) {
      const response = await fetch('https://your-planetscale-endpoint', {
        method: 'POST',
        headers: { 'Content-Type': 'application/json' },
        body: JSON.stringify({ sql, params })
      });
      return await response.json();
    }
  3. 3

    Update Prisma Configuration

    Modify Prisma's configuration files to recognize the new PlanetScale serverless driver. This includes adding an entry in the database connector options to allow users to specify the PlanetScale driver in their Prisma schema.

    prisma
    datasource db {
      provider = "planetscale_serverless"
      url      = env("PLANETSCALE_DATABASE_URL")
    }
  4. 4

    Test the New Driver

    Create unit tests to validate the functionality of the new driver. Ensure that it can handle various SQL queries and that it integrates seamlessly with Prisma's existing features.

    typescript
    test('should execute a query', async () => {
      const result = await planetscaleDriver.query('SELECT * FROM users');
      expect(result).toBeDefined();
    });
  5. 5

    Documentation and Examples

    Update the Prisma documentation to include examples and usage instructions for the new PlanetScale serverless driver. This will help users understand how to implement it in their projects.

Validation

To confirm the fix worked, deploy the updated Prisma version and run a sample application using the PlanetScale serverless driver. Verify that database operations execute correctly without errors and that the application behaves as expected.

Sign in to verify this fix

Environment

Submitted by

AC

Alex Chen

2450 rep

Tags

prismaormpostgresqlkind/featuretopic:-serverlesstopic:-connectortopic:-mysql