Install this version
v0.1.2rune add @rune/mysql@0.1.2Manifest hash sha256:153fe507d7fe397baa64d25c2f13d4e78cc452fa20a1c9a9d1658b93e72ded84
runebook · rune
MySQL and MariaDB adapter for Rune storage using prepared statements.
Library Rune. Boilerplate code consumed by other Runes — the host never loads it directly. Install it as a dependency of your own Rune and import from it.
rune add @rune/mysql@0.1.2Manifest hash sha256:153fe507d7fe397baa64d25c2f13d4e78cc452fa20a1c9a9d1658b93e72ded84
The author declares these capabilities as a guide. Rune scripts run with server access.
No capabilities declared by the author. Rune scripts run with server access.
Use MySQL as a database for @rune/storage documents, @rune/web-auth accounts, or a stateful Paper Rune.
rune add @rune/mysql
Create the database before connecting. Use a mysql: URL. The application user needs read and write access and permission to create the table on first use.
Set DATABASE_URL in the process environment for this example.
Example URL shape:
mysql://user:password@127.0.0.1:3306/rune
import { connect } from "@rune/mysql";
import { document } from "@rune/storage";
const db = await connect(process.env.DATABASE_URL!, {
name: "shared",
table: "rune_auth",
});
const visits = document(db.store, "lobby:visits", () => ({ total: 0 }));
await visits.update(({ total }) => ({ total: total + 1 }));
name registers the open connection for other Runes in the same server process.
For example, RUNE_HOMES_STORAGE=reuse:shared makes Homes use this connection.
Omit the name for a generated name or set it to false for a private connection.
Only the connection owner should call await db.close() when consumers have stopped.
table defaults to rune_auth. The adapter creates the table with an index for expiration, and uses parameterized queries for record operations.
await mysqlStore(pool, table?) wraps an existing mysql2-compatible pool. db.pool exposes the pool created by connect. When you wrap a driver yourself, you own its lifecycle. See the shared storage configuration for plugin environment variables and connection modes.