mcpField
G
grdb

grdb

github.com/johnrogersData & databases233163 installsUpdated 41w ago
Repository

About grdb

A reference skill for using GRDB.swift, a type-safe Swift wrapper for direct SQLite access. It guides developers through database setup, queries, migrations, reactive observation, and performance checks.

Key features

  1. 01Setting up DatabaseQueue or DatabasePool
  2. 02Writing SQL and QueryInterface queries
  3. 03Defining schema migrations
  4. 04Observing query results reactively
  5. 05Profiling queries and indexes

Use cases

  1. 01Structuring a SQLite database in a Swift app
  2. 02Evolving schemas through migrations
  3. 03Updating SwiftUI views from query changes
  4. 04Checking query plans before optimization

Install

Copy the command and run it in a terminal.

$npx skills add https://github.com/johnrogers/claude-swift-engineering --skill grdb

After installing, type/grdbin Claude Code to confirm it loaded.

Bundled files

References and scripts installed along with SKILL.md.

references/
getting-started.md
migrations.md
performance.md
queries.md
value-observation.md

Details

From the project README

GRDB

Direct SQLite access using GRDB.swift - type-safe Swift wrapper with full SQLite power when you need it.

Reference Loading Guide

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.

ReferenceLoad When
Getting StartedSetting up DatabaseQueue or DatabasePool
QueriesWriting raw SQL, Record types, type-safe queries
Value ObservationReactive queries, SwiftUI integration
MigrationsDatabaseMigrator, schema evolution
PerformanceEXPLAIN QUERY PLAN, indexing, profiling

When to Use GRDB vs SQLiteData

ScenarioUse
Type-safe @Table modelsSQLiteData
CloudKit sync neededSQLiteData
Complex joins (4+ tables)GRDB
Window functions (ROW_NUMBER, RANK)GRDB
Performance-critical raw SQLGRDB
Reactive queries (ValueObservation)GRDB

Core Workflow

  1. Choose DatabaseQueue (single connection) or DatabasePool (concurrent reads)
  2. Define migrations with DatabaseMigrator
  3. Create Record types (Codable, FetchableRecord, PersistableRecord)
  4. Write queries with raw SQL or QueryInterface
  5. Use ValueObservation for reactive updates

Requirements

  • iOS 13+, macOS 10.15+
  • Swift 5.7+
  • GRDB.swift 6.0+

Common Mistakes

  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.

  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.

  3. Improper migration ordering — Running migrations out of order or skipping intermediate versions breaks schema consistency. Always apply migrations sequentially; never jump versions.

  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.

  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.

Comments

Markdown supported