Waddler <> PlanetScale
This guide assumes familiarity with:
- Database connection basics with Waddler
- PlanetScale database - website
- PlanetScale http driver - GitHub
- Waddler MySQL drivers - docs
According to the official website, PlanetScale is the world’s most advanced serverless MySQL platform.
With Waddler you can access PlanetScale over http
through their official database-js
driver from serverless and serverfull environments with our waddler/planetscale-serverless
package.
You can also access PlanetScale through TCP with mysql2
driver — see here.
Step 1 - Install packages
npm
yarn
pnpm
bun
npm i waddler @planetscale/database
Step 2 - Initialize the driver and make a query
import { waddler } from "waddler/planetscale-serverless";
const sql = waddler({ connection: {
host: process.env["DATABASE_HOST"],
username: process.env["DATABASE_USERNAME"],
password: process.env["DATABASE_PASSWORD"],
}});
const result = await sql`select 1;`;
If you need to provide your existing driver
import { waddler } from "waddler/planetscale-serverless";
import { Client } from "@planetscale/database";
const client = new Client({
host: process.env["DATABASE_HOST"],
username: process.env["DATABASE_USERNAME"],
password: process.env["DATABASE_PASSWORD"],
});
const sql = waddler({ client });
const result = await sql`select 1;`;
Make sure to checkout the PlanetScale official MySQL courses, we think they’re outstanding 🙌