Why D1?
Cloudflare D1 is a serverless SQLite database that runs at the edge. Combined with Drizzle ORM, it provides a type-safe, performant data layer.
Schema Design
import { sqliteTable, text, integer } from "drizzle-orm/sqlite-core"
export const posts = sqliteTable("posts", {
id: text("id").primaryKey(),
title: text("title").notNull(),
content: text("content").notNull(),
status: text("status").default("draft"),
})
Querying with Drizzle
const published = await db.query.posts.findMany({
where: eq(posts.status, "published"),
orderBy: [desc(posts.createdAt)],
})
Benefits
- Zero egress fees: Unlike traditional databases
- SQLite compatibility: Battle-tested SQL engine
- Global replication: Data close to your users