@storyshelf/db-mysql
@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.
Install
Section titled “Install”npm i @storyshelf/db-mysqlpnpm add @storyshelf/db-mysqlyarn add @storyshelf/db-mysql- npm package — install tarballs and version history.
- Source on GitHub — package directory on
main.
Configure
Section titled “Configure”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(withport,user,password,database,ssl,connectionLimit) — discrete options; the pool defaults to 10 connections.client— a preconfiguredmysql2pool 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.
Presets
Section titled “Presets”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.
Other exports
Section titled “Other exports”| Subpath | Contents |
|---|---|
@storyshelf/db-mysql/schema | The Drizzle table definitions. |
@storyshelf/db-mysql/ddl | The canonical DDL string for every table and index, for provisioning outside the adapter. |
When to use it
Section titled “When to use it”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.