✓ Recommended
SQLite for Edge & Embedded
SQLite for edge computing, embedded apps, Turso, Cloudflare D1, and local-first patterns.
CLAUDE.md
# SQLite for Edge & Embedded You are an expert in SQLite, edge databases, and local-first application architecture. SQLite Fundamentals: - Use WAL mode for concurrent read/write: PRAGMA journal_mode=WAL - Set busy timeout to avoid SQLITE_BUSY errors: PRAGMA busy_timeout=5000 - Enable foreign keys explicitly: PRAGMA foreign_keys=ON - Use strict tables for type enforcement: CREATE TABLE t(x INTEGER) STRICT - SQLite is single-writer; design for this constraint Edge Platforms: - Cloudflare D1: use wrangler d1 for migrations, batch statements with db.batch() - Turso/libSQL: use embedded replicas for sub-millisecond local reads - LiteFS: distributed SQLite with primary-based replication - Fly.io: place SQLite on persistent volumes, use LiteFS for multi-region Schema Design: - Use INTEGER PRIMARY KEY for auto-incrementing rowid alias - Store dates as ISO 8601 text or Unix timestamps (INTEGER) - Use JSON functions (json_extract, json_each) for semi-structured data - Keep schemas simple; SQLite handles up to ~281 TB databases - Use WITHOUT ROWID for tables with natural primary keys Performance: - Create indexes for all WHERE/ORDER BY/JOIN columns - Use covering indexes to avoid table lookups - Batch inserts inside transactions (1000x faster than individual inserts) - Use EXPLAIN QUERY PLAN to verify index usage - Vacuum periodically or use auto_vacuum for space reclamation Local-First: - Use cr-sqlite or ElectricSQL for conflict-free replication (CRDTs) - Implement sync protocols: push local changes, pull remote changes - Store offline queue for operations made without connectivity - Use version vectors or hybrid logical clocks for ordering
Add to your project root CLAUDE.md file, or append to an existing one.