PlanetScale

Reylo on PlanetScale's MySQL and Postgres databases

A PlanetScale MySQL database is MySQL, so everything on the MySQL page holds for it.

DialectMySQL, served through Vitess; a PlanetScale Postgres database is Postgres
What the type check readsA MySQL 8.0.38 or later server with your schema, such as a local one
Drivers@planetscale/database 1.x, mysql2 and Drizzle
SchemaThe migrations you deploy to PlanetScale, applied to that server too
MonitoringInsights shows the .sql file each query came from

Drivers

Pass a client from @planetscale/database, mysql2 or Drizzle to .run().

@planetscale/database

Pass a connection from connect(), a Client, or the transaction that .transaction() hands its callback:

// @planetscale/database 1.x: a 2.0 client is a type error
import {  } from "@planetscale/database";
import  from "./get_user.sql";

const  = ({ : .. });
const user = await .(, { : 1 });
const user: {
    id: number;
    name: string;
    email: string | null;
} | null
await .(() => .(, { : 1 }));
select id, name, email
from 
where id = :id

About the driver:

  • Version 2.0 isn't supported, since it can't bind parameters.
  • The driver sends each query over HTTP, so it runs where there are no TCP sockets, as in Cloudflare Workers.
  • It rounds a FLOAT to its shorter text, such as 1.1. The mysql2 driver returns its exact value.

mysql2

Pass a pool, or a connection taken from one, which can run a transaction:

import  from "mysql2/promise";
import  from "./get_user.sql";

const  = .(..);
const  = await .(, { : 1 });

const  = await .();
await .();
await .(, { : 1 });
await .();
.();
select id, name, email
from 
where id = :id

PlanetScale's connection string for Node ends with an ssl setting, which mysql2 reads to check the server's certificate:

.env
DATABASE_URL=mysql://…/app?ssl={"rejectUnauthorized":true}

Drizzle

Pass a Drizzle connection made over a Client from @planetscale/database:

import {  } from "@planetscale/database";
import {  } from "drizzle-orm/planetscale-serverless";
import  from "./get_user.sql";

const  = (new ({ : .. }));
const  = await .(, { : 1 });
select id, name, email
from 
where id = :id

Local database

The type check reads a MySQL server with your schema. PlanetScale serves MySQL through Vitess, which the type check isn't tested on, so run MySQL 8.0.38 or later locally:

Terminal
docker run -d -p 3306:3306 -e MYSQL_DATABASE=app \
  -e MYSQL_ALLOW_EMPTY_PASSWORD=yes mysql:8.4

Point direct_url at it:

.reylo.yaml
# local mysql, migrations applied
direct_url: mysql://root@127.0.0.1:3306/app

Why a local server:

  • Set it in .reylo.yaml, so that DATABASE_URL stays your app's PlanetScale connection string. Without it, the type check reads DATABASE_URL.
  • Your queries still run on PlanetScale, through the client you pass to .run().

Schema

Apply each migration you deploy to PlanetScale to the local server too, with the same tool:

Terminal
for file in migrations/*.sql; do
  mysql -h 127.0.0.1 -u root app < "$file"
done

With other tools:

Insights

Each query Reylo sends ends with a sqlcommenter comment that names its file. PlanetScale's Insights reads it as the query's file tag:

What Reylo sends for queries/get_user.sql, by default
select id, name, email from  where id = ? /*file='queries%2Fget_user.sql'*/

PlanetScale Postgres

A PlanetScale Postgres database is Postgres. Point direct_url at its direct connection on port 5432. PgBouncer, on port 6432, can fail to describe a query:

.env
# pgbouncer, for your app
DATABASE_URL=postgres://…:6432/…
# the direct connection, for the type check
DIRECT_DATABASE_URL=postgres://…:5432/…

Then point Reylo at the direct connection:

.reylo.yaml
direct_url: ${DIRECT_DATABASE_URL}

Run your queries with any Postgres driver.

Released under the MIT License. Copyright © 2026 Colin McDonnell.

On this page

reylosql/reylo