new·The score now tells you which way it movedA brain's exam only ever grows: its own material writes questions, and so does every question a real caller asked and did not get answered. The score is a percentage over that growing set, so a brain that learned more could post a smaller number — and this week three did. One of them answered two MORE questions than the week before and showed eighteen points less. Printed as a single percentage, that reads as decline to a reader and as punishment to anyone who contributes material.all news →
mozg.beta
Sign in

Drizzle · SQLite · all subjects

d1

10 notes, read out of this brain and free to use. Each one was extracted from a source and is re-checked against its exam.

D1 is Cloudflare's queryable relational database

D1 is Cloudflare's first queryable relational database. Drizzle ORM fully supports the Cloudflare D1 database and Cloudflare Workers environment.

D1 query methods syntax

Drizzle ORM for D1 mirrors popular SQLite-like query methods: all, get, values, and run.

D1 setup requires wrangler.json or wrangler.toml

To use Drizzle with D1, you need a wrangler.json or wrangler.toml configuration file. The file must include a d1_databases array with at least one database configuration.

D1 wrangler.json configuration fields

The D1 database configuration in wrangler.json includes: binding (the environment variable name), database_name (the database name), database_id (the database identifier), and migrations_dir (path to migrations directory, typically 'drizzle/migrations').

D1 wrangler.toml configuration fields

The D1 database configuration in wrangler.toml uses [[ d1_databases ]] table syntax with fields: binding, database_name, database_id, and migrations_dir.

Install packages for D1

To use Drizzle with D1, install drizzle-orm@rc and drizzle-kit@rc as a development dependency.

Initialize D1 driver with drizzle function

Import the drizzle function from 'drizzle-orm/d1' and initialize it with the D1 database binding from the environment.

D1 basic query example in Cloudflare Worker

Example showing how to query D1 in a Cloudflare Worker: import { drizzle } from 'drizzle-orm/d1'; export interface Env { <BINDING_NAME>: D1Database; } export default { async fetch(request: Request, env: Env) { const db = drizzle(env.<BINDING_NAME>); const result = await db.select().from(users).all() return Response.json(result); }, };

D1 requires nodejs_compat compatibility flag

When using D1 with Drizzle in Cloudflare Workers, include 'nodejs_compat' in the compatibility_flags array in wrangler.json.

Cloudflare D1 dbCredentials configuration

For Cloudflare D1, use dialect 'sqlite' with driver 'd1-http'. dbCredentials requires three fields: accountId (string), databaseId (string), and token (string).

Give your agent this brain