PostgresPostgres through Hyperdrive.
Your Elm route stays small: it calls Loader.query, Loader.queryOne, or Loader.execute. The Worker owns the Postgres connection through Hyperdrive and adapts elm-ssr SQL effects to your database client.
- Create Postgres in your provider: Neon, Supabase, RDS, Timescale, CockroachDB, or another compatible host.
- Create a Hyperdrive configuration from that database connection string.
- Bind it as HYPERDRIVE, then read env.HYPERDRIVE.connectionString in the Worker.
ExampleAdapt elm-ssr SQL effects to Postgres.
The shape is intentionally boring: create a Postgres client from the binding, run the SQL effect, return rows plus rowCount, and close the client.
import { inMemoryEffects } from "elm-ssr/effects";
import { postgresSql } from "elm-ssr/backends";
import { Client } from "pg";
const effects = async (effect, ctx) =>
inMemoryEffects({
sql: postgresSql({
run: async (sql, params) => {
const client = new Client({
connectionString: ctx.env.HYPERDRIVE.connectionString
});
await client.connect();
try {
const result = await client.query(sql, params);
return { rows: result.rows, rowCount: result.rowCount ?? 0 };
} finally {
await client.end();
}
}
})
})(effect, ctx);
npx wrangler hyperdrive create app-db \
--connection-string="postgres://USER:PASS@HOST:5432/DB"
"hyperdrive": [
{ "binding": "HYPERDRIVE", "id": "<hyperdrive-id>" }
]