Drizzle | Cloudflare D1 HTTP API with Drizzle Kit
This guide assumes familiarity with:
- Drizzle Kit
- Drizzle Studio
- Drizzle Chrome Extension
- You should have installed
drizzle-kit@0.21.3or higher - You should have Cloudflare account, deployed D1 database and token with D1 edit permissions
To use Drizzle kit with Cloudflare D1 HTTP API, you need to configure the drizzle.config.ts file like this:
import { defineConfig } from 'drizzle-kit';
export default defineConfig({
schema: './src/schema.ts',
out: './migrations',
dialect: 'sqlite',
driver: 'd1-http',
dbCredentials: {
accountId: process.env.CLOUDFLARE_ACCOUNT_ID!,
databaseId: process.env.CLOUDFLARE_DATABASE_ID!,
token: process.env.CLOUDFLARE_D1_TOKEN!,
},
});You can find accountId, databaseId and token in Cloudflare dashboard.
- To get
accountIdgo to Workers & Pages -> Overview -> copy Account ID from the right sidebar. - To get
databaseIdopen D1 database you want to connect to and copy Database ID. - To get
tokengo to My profile -> API Tokens and create token with D1 edit permissions.
After you have configured drizzle.config.ts file, Drizzle Kit lets you run migrate, push, introspect and studio commands using Cloudflare D1 HTTP API.
You can also use Drizzle Chrome Extension to browse Cloudflare D1 database directly in their admin panel.