Landscape β€” team collaboration
EngineeringTechnology

D1 Deep Dive: SQLite at the Edge for Production Workloads

1 min

What is D1?

D1 is Cloudflare's serverless SQL database based on SQLite. Think of it as SQLite with superpowers: edge replication, automatic backups, and HTTP-based access.

Landscape β€” team collaboration

Why SQLite?

SQLite processes more SQL queries than all other database engines combined. It's used in every smartphone, every browser, and now β€” every edge location.

  • Single-file database β€” no daemon, no config
  • ACID compliant with WAL mode
  • Read performance: millions of queries/second
  • 1014 (10 trillion) SQLite databases in active use worldwide

Schema Management with Payload

Payload automatically manages your D1 schema through drizzle-orm. When you add a field to a collection, Payload generates the migration:

TypeScript
1// Payload auto-generates SQL migrations2// Run: npx payload migrate3ALTER TABLE posts ADD COLUMN "featured" integer DEFAULT false;4CREATE INDEX IF NOT EXISTS "posts_featured_idx" ON "posts" ("featured");

Query Patterns

TypeScript
1// Local API β€” type-safe, no HTTP overhead2const featured = await payload.find({3  collection: 'posts',4  where: {5    featured: { equals: true },6    _status: { equals: 'published' },7  },8  sort: '-publishedAt',9  limit: 5,10  depth: 2,11})12 13// REST API equivalent:14// GET /api/posts?where[featured][equals]=true&sort=-publishedAt

Backup & Recovery

D1 provides time-travel recovery β€” restore your database to any point within the last 30 days.

EngineeringTechnology

Comments

0/2000

Related Posts