Install this version
v0.1.2Manifest hash sha256:6d5a99dc39bd1df7a2908022992fad17294f45c6ff8d973e5e8d8c76682828af
runebook · rune
PostgreSQL adapter for Rune storage backed by node-postgres pools.
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.
Manifest hash sha256:6d5a99dc39bd1df7a2908022992fad17294f45c6ff8d973e5e8d8c76682828af
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.
rune add @rune/postgres@0.1.2Use PostgreSQL as a database for @rune/storage documents, @rune/web-auth accounts, or a stateful Paper Rune.
rune add @rune/postgres
Create the database before connecting. Use a postgres: or postgresql: URL. The application role needs read and write access and permission to create the table and index in the selected schema.
Set DATABASE_URL in the process environment for this example.
Example URL shape:
postgresql://user:password@127.0.0.1:5432/rune
import { connect } from "@rune/postgres";
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 and expiration index, and uses parameterized queries.
await postgresStore(pool, table?) wraps an existing pg-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.