Skip to content
Database: Bring your own
FrameworkDatabase: Bring your own
On this page

Database: Bring your own

Use D1 for the built-in workflow, or connect to a service through an API that runs on Workers.

What Goribu configures

Goribu currently provisions one D1 database through database: { type: "d1", name }. It does not have configuration fields or automatic provisioning for PostgreSQL, MySQL, or Hyperdrive.

Hyperdrive integration is not available in the current Goribu configuration API. Do not add a made-up hyperdrive field or edit generated Wrangler files to work around it.

Use a provider's HTTP API

A service with an HTTPS API can be called from a handler using fetch. Keep its credentials in server environment values. This example assumes your service accepts a bearer token and returns JSON:

src/lib/catalog.server.js
// Adapt this path and response handling to your provider's documented API.
export async function readProducts(env) {
  const response = await fetch(new URL("/products", env.CATALOG_API_URL), {
    headers: { Authorization: `Bearer ${env.CATALOG_API_TOKEN}` },
  });
  if (!response.ok) throw new Error("The catalog request failed.");
  return response.json();
}
src/routes/products.js
import { readProducts } from "../lib/catalog.server.js";

// Only return fields that this endpoint is allowed to expose.
export async function GET(req, res) {
  const products = await readProducts(req.env);
  return res.json(products);
}

Set the two variables in .env locally and .env.production for deployment. The provider controls its endpoint, authentication, validation, consistency, and error behavior; adapt the helper to those rules.

Using an SDK or query builder

Check that a library supports Cloudflare Workers before choosing it. A Node.js driver is not automatically compatible with the Workers runtime. Goribu does not create a connection pool or manage an external service's schema for you.

For query builders on D1, req.d1.session provides the request's session while preserving Goribu's default consistency behavior. req.d1.binding exposes the raw binding when an integration specifically requires it. See D1.

Keep the boundary clear

Place private clients and credentials in server-only modules outside src/routes/. Import them from handlers, and send only the data needed by the page through res.render().

Use your provider's migration and deployment tools for its database. Goribu's migration commands apply only to D1.