---
title: "D1"
description: "A Cloudflare D1 billing database."
---

> **Source:** [`packages/paykit/src/Database/D1.ts`](https://github.com/potion-run/paykit/blob/main/packages/paykit/src/Database/D1.ts#L14)
> **Kind:** Layer · **Product:** D1 · **Provides:** `paykit/Database` · **Peer dependencies:** `@alchemy.run/cloudflare`

A Cloudflare D1 billing database.

At runtime the Worker reaches the database through its native binding (the
layer pulls in `Cloudflare.D1.QueryDatabaseBinding`). At migration time the
deploy uses the D1 HTTP query API — which also targets the local simulator
under `alchemy dev` — so the Worker's binding is never used outside the
runtime, and the migration code is tree-shaken out of the deployed bundle.
The structure is Alchemy's own `CloudflareD1` layer for Better Auth, with
paykit's executor in place of the Kysely one.

Import it from `@potion.run/paykit/Database/D1`, not the barrel: it carries
`@alchemy.run/cloudflare`, an optional peer.

## A D1-backed model

```ts
const Db = Cloudflare.D1.Database("BillingDb");

Effect.gen(function* () {
  const stack = yield* Paykit.BillingStack("Billing", { ...billing, migrate: true });
  return { tiers: stack.tiers };
}).pipe(Effect.provide(D1(Db)));
```
