D1StateStore
D1StateStore provides a State Store using Cloudflare D1 databases for serverless, distributed SQLite state management.
-
Configure D1StateStore
Update your
alchemy.run.ts
to use Cloudflare D1 state storage:import alchemy from "alchemy";import { D1StateStore } from "alchemy/cloudflare";const app = await alchemy("my-app", {stateStore: (scope) => new D1StateStore(scope)});// Your resources here...await app.finalize(); -
Run your app
Execute your Alchemy script to initialize the D1 state store:
Terminal window bun ./alchemy.run.tsTerminal window npx tsx ./alchemy.run.tsTerminal window pnpm tsx ./alchemy.run.tsTerminal window yarn tsx ./alchemy.run.tsAlchemy automatically creates a D1 database named
alchemy-state
in your Cloudflare account. -
Verify the state store
Check your Cloudflare dashboard to see the D1 database:
https://dash.cloudflare.com/d1You should see an
alchemy-state
database handling your application state. -
View database contents
Use the Cloudflare dashboard or Wrangler CLI to inspect your state:
Terminal window wrangler d1 execute alchemy-state --command "SELECT * FROM resources LIMIT 10"