$npx -y skills add johnrogers/claude-swift-engineering --skill grdbUse when writing raw SQL with GRDB, complex joins across 4+ tables, window functions, ValueObservation for reactive queries, or dropping down from SQLiteData for performance. Direct SQLite access for iOS/macOS with type-safe queries and migrations.
| 1 | # GRDB |
| 2 | |
| 3 | Direct SQLite access using [GRDB.swift](https://github.com/groue/GRDB.swift) - type-safe Swift wrapper with full SQLite power when you need it. |
| 4 | |
| 5 | ## Reference Loading Guide |
| 6 | |
| 7 | **ALWAYS load reference files if there is even a small chance the content may be required.** It's better to have the context than to miss a pattern or make a mistake. |
| 8 | |
| 9 | | Reference | Load When | |
| 10 | |-----------|-----------| |
| 11 | | **[Getting Started](references/getting-started.md)** | Setting up DatabaseQueue or DatabasePool | |
| 12 | | **[Queries](references/queries.md)** | Writing raw SQL, Record types, type-safe queries | |
| 13 | | **[Value Observation](references/value-observation.md)** | Reactive queries, SwiftUI integration | |
| 14 | | **[Migrations](references/migrations.md)** | DatabaseMigrator, schema evolution | |
| 15 | | **[Performance](references/performance.md)** | EXPLAIN QUERY PLAN, indexing, profiling | |
| 16 | |
| 17 | ## When to Use GRDB vs SQLiteData |
| 18 | |
| 19 | | Scenario | Use | |
| 20 | |----------|-----| |
| 21 | | Type-safe @Table models | SQLiteData | |
| 22 | | CloudKit sync needed | SQLiteData | |
| 23 | | Complex joins (4+ tables) | GRDB | |
| 24 | | Window functions (ROW_NUMBER, RANK) | GRDB | |
| 25 | | Performance-critical raw SQL | GRDB | |
| 26 | | Reactive queries (ValueObservation) | GRDB | |
| 27 | |
| 28 | ## Core Workflow |
| 29 | |
| 30 | 1. Choose DatabaseQueue (single connection) or DatabasePool (concurrent reads) |
| 31 | 2. Define migrations with DatabaseMigrator |
| 32 | 3. Create Record types (Codable, FetchableRecord, PersistableRecord) |
| 33 | 4. Write queries with raw SQL or QueryInterface |
| 34 | 5. Use ValueObservation for reactive updates |
| 35 | |
| 36 | ## Requirements |
| 37 | |
| 38 | - iOS 13+, macOS 10.15+ |
| 39 | - Swift 5.7+ |
| 40 | - GRDB.swift 6.0+ |
| 41 | |
| 42 | ## Common Mistakes |
| 43 | |
| 44 | 1. **Performance assumptions without EXPLAIN PLAN** — Assuming your query is fast or slow without checking `EXPLAIN QUERY PLAN` is guessing. Always profile queries with EXPLAIN before optimizing. |
| 45 | |
| 46 | 2. **Missing indexes on WHERE clauses** — Queries filtering on non-indexed columns scan the entire table. Index any column used in WHERE, JOIN, or ORDER BY clauses for large tables. |
| 47 | |
| 48 | 3. **Improper migration ordering** — Running migrations out of order or skipping intermediate versions breaks schema consistency. Always apply migrations sequentially; never jump versions. |
| 49 | |
| 50 | 4. **Record conformance shortcuts** — Not conforming Record types to `PersistableRecord` or `FetchableRecord` correctly leads to silent data loss or deserialization failures. Always implement all required protocols correctly. |
| 51 | |
| 52 | 5. **ValueObservation without proper cleanup** — Forgetting to cancel ValueObservation when views disappear causes memory leaks and stale data subscriptions. Store the cancellable and clean up in deinit. |