VibORM

PlanetScale

Serverless MySQL driver for PlanetScale

Installation

pnpm add @planetscale/database

Configuration

import { createClient } from "viborm/drivers/planetscale";

const client = createClient({
  databaseUrl: process.env.DATABASE_URL,
  schema,
});

Options

OptionTypeDescription
clientClientExisting PlanetScale client
databaseUrlstringPlanetScale connection URL
optionsConfigPlanetScale configuration options

Using Options

import { createClient } from "viborm/drivers/planetscale";

const client = createClient({
  options: {
    host: process.env.DATABASE_HOST,
    username: process.env.DATABASE_USERNAME,
    password: process.env.DATABASE_PASSWORD,
  },
  schema,
});

Transactions & Batching

PlanetScale driver supports full transactions via the @planetscale/database Client's transaction() method.

Dynamic Transactions

Use the callback API when operations need to depend on each other:

await client.$transaction(async (tx) => {
  const user = await tx.user.create({
    data: { name: "Alice", email: "alice@example.com" },
  });

  await tx.post.create({
    data: { title: "Hello", authorId: user.id },
  });
});

Batch Mode

Use the array API for independent operations:

const [users, posts] = await client.$transaction([
  client.user.findMany(),
  client.post.findMany(),
]);

Migrations

Migrations run atomically using transactions - all statements succeed or none are applied.

Capabilities

FeatureSupport
Dynamic transactionsFull
Batch modeFull (transaction wrapper)
Migration atomicityFull

Limitations

  • No RETURNING clause - uses LAST_INSERT_ID()
  • JSON columns return as strings and are parsed automatically
  • Boolean values stored as TINYINT(1)

Serverless Usage

PlanetScale driver is optimized for serverless environments:

// Cloudflare Workers, Vercel Edge, etc.
export default {
  async fetch(request: Request) {
    const client = createClient({
      databaseUrl: process.env.DATABASE_URL,
      schema,
    });

    const users = await client.user.findMany();
    return Response.json(users);
  },
};

On this page