npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

drizzle-d1-config

v1.0.1

Published

Drizzle config helpers for Cloudflare D1

Readme

drizzle-d1-config

A helper for easily configuring drizzle.config.ts when using Cloudflare D1. Automatically resolves the necessary settings from wrangler.jsonc and other sources.

Japanese >

Install

pnpm add drizzle-d1-config

Usage

HTTP (Remote)

// drizzle.config.ts
import { defineConfig } from 'drizzle-kit'
import { d1Config } from 'drizzle-d1-config/http'

export default defineConfig({
  ...d1Config(),
  schema: './src/db/schema.ts',
})

This generates a config like the following.

{
  out: migrationsDir,
  dialect: 'sqlite',
  driver: 'd1-http',
  dbCredentials: {
    accountId,
    databaseId,
    token,
  },
}

Local

// drizzle.config.ts
import { defineConfig } from 'drizzle-kit'
import { d1Config } from 'drizzle-d1-config/local'

export default defineConfig({
  ...d1Config(),
  schema: './src/db/schema.ts',
})

This generates a config like the following.

{
  out: migrationsDir,
  dialect: 'sqlite',
  dbCredentials: {
    url: localSqlitePath,
  },
}

Options

All options are optional.

HTTP

| Option | Description | Note | | -------------------- | -------------------------- | -------------------------------------------------------------------- | | out | Migration output directory | | | binding | D1 binding name | Required if multiple D1 databases exist | | wranglerConfigPath | Wrangler config file path | wrangler.jsonc, wrangler.toml, wrangler.json are auto-detected | | accountId | Cloudflare account ID | | | databaseId | D1 database ID | | | token | Cloudflare API token | |

Local

| Option | Description | Note | | -------------------- | -------------------------- | -------------------------------------------------------------------- | | out | Migration output directory | | | binding | D1 binding name | Required if multiple D1 databases exist | | wranglerConfigPath | Wrangler config file path | wrangler.jsonc, wrangler.toml, wrangler.json are auto-detected | | databaseId | D1 database ID | | | persistDir | Wrangler state directory | Required if using --persist-to with Wrangler |

Resolution Details

Each value is resolved in the following priority order. The wrangler config file is searched in this order across all fields.

  1. wrangler.jsonc
  2. wrangler.toml
  3. wrangler.json

If multiple entries exist in d1_databases, you need to specify the binding name of the target DB. If there is only one, it is resolved automatically.

accountId (HTTP)

  1. Explicitly provided argument
  2. account_id from the wrangler config file
  3. account.id from ./node_modules/.cache/wrangler/wrangler-account.json

databaseId (HTTP, Local)

  1. Explicitly provided argument
  2. database_id of the matching DB in d1_databases from the wrangler config file

migrationsDir (HTTP, Local)

  1. Explicitly provided argument
  2. migrations_dir of the matching DB in d1_databases from the wrangler config file

token (HTTP)

  1. Explicitly provided argument
  2. Retrieved from the output of wrangler auth token --json
    • The package manager is detected automatically.

localSqlitePath (Local)

The path to a local SQLite file such as .wrangler/state/v3/d1/miniflare-D1DatabaseObject/*.sqlite. Computed from databaseId. (ref: cloudflare/workers-sdk/miniflare)

Tips

Here are two ways to switch between local and remote configurations.

Environment Variable

// drizzle.config.ts
import { defineConfig } from 'drizzle-kit'
import { d1Config as d1HttpConfig } from 'drizzle-d1-config/http'
import { d1Config as d1LocalConfig } from 'drizzle-d1-config/local'

const isLocal = process.env.NODE_ENV === 'development'

export default defineConfig({
  ...(isLocal ? d1LocalConfig() : d1HttpConfig()),
  schema: './src/db/schema.ts',
})

Separate Files

// drizzle.config.ts
import { defineConfig } from 'drizzle-kit'
import { d1Config } from 'drizzle-d1-config/local'

export default defineConfig({
  ...d1Config(),
  schema: './src/db/schema.ts',
})
// drizzle.remote.config.ts
import { defineConfig } from 'drizzle-kit'
import { d1Config } from 'drizzle-d1-config/http'

export default defineConfig({
  ...d1Config(),
  schema: './src/db/schema.ts',
})

Specify the config file when running drizzle-kit:

// package.json
{
  "scripts": {
    "db:migrate:local": "drizzle-kit migrate",
    "db:migrate:remote": "drizzle-kit migrate --config ./drizzle.remote.config.ts",
    "db:studio:local": "drizzle-kit studio",
    "db:studio:remote": "drizzle-kit studio --config ./drizzle.remote.config.ts",
  },
}

License

MIT