Skip to content

@storyshelf/db-mysql

View as Markdown

@storyshelf/db-mysql connects StoryShelf to MySQL or MariaDB through mysql2 and Drizzle ORM. It implements the same DatabaseAdapter contract as SQLite and Postgres, so the rest of the application does not change when you switch databases.

Terminal window
npm i @storyshelf/db-mysql
import { createMysqlDatabase } from "@storyshelf/db-mysql";
const database = createMysqlDatabase({
url: process.env.DATABASE_URL!, // mysql://user:pass@host:3306/shelf
});

Provide one of:

  • url / connectionString — a MySQL connection URL.
  • host (with port, user, password, database, ssl, connectionLimit) — discrete options; the pool defaults to 10 connections.
  • client — a preconfigured mysql2 pool or connection. When you inject a client you own its lifecycle; the adapter only closes pools it created.

Migrations run inside the adapter's migrate hook — await them via app.lifecycle.setup() after creating the app. The adapter implements DatabaseAdapter (insert, update, get, remove, list, count, all) plus a ping used by health checks.

Two preset entry points exist so generated servers and the CLI can import a provider-named factory:

import { createPlanetscaleDatabase } from "@storyshelf/db-mysql/planetscale";
import { createTidbDatabase } from "@storyshelf/db-mysql/tidb";

Today both are thin aliases over the same mysql2 pool: PlanetScale and TiDB Serverless speak the MySQL wire protocol, so the standard options above work unchanged (use ssl as your provider requires). They take the same options as createMysqlDatabase.

SubpathContents
@storyshelf/db-mysql/schemaThe Drizzle table definitions.
@storyshelf/db-mysql/ddlThe canonical DDL string for every table and index, for provisioning outside the adapter.

Choose MySQL or MariaDB when that is what your team already runs or your platform provides. Pair it with local storage for single-node deployments, or S3-compatible storage when instances do not share a filesystem.