Skip to content
GitHubXDiscord

D1StateStore

D1StateStore provides a State Store using Cloudflare D1 databases for serverless, distributed SQLite state management.

  1. 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();
  2. Run your app

    Execute your Alchemy script to initialize the D1 state store:

    Terminal window
    bun ./alchemy.run.ts

    Alchemy automatically creates a D1 database named alchemy-state in your Cloudflare account.

  3. Verify the state store

    Check your Cloudflare dashboard to see the D1 database:

    https://dash.cloudflare.com/d1

    You should see an alchemy-state database handling your application state.

  4. 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"