Code
GRDB – A toolkit for SQLite databases, with a focus on application development

Use this library to save your application’s permanent data into SQLite databases. It comes with built-in tools that address common needs:
-
SQL Generation
Enhance your application models with persistence and fetching methods, so that you don’t have to deal with SQL and raw database rows when you don’t want to.
-
Database Observation
Get notifications when database values are modified.
-
Robust Concurrency
Multi-threaded applications can efficiently use their databases, including WAL databases that support concurrent reads and writes.
-
Migrations
Evolve the schema of your database as you ship new versions of your application.
-
Leverage your SQLite skills
Not all developers need advanced SQLite features. But when you do, GRDB is as sharp as you want it to be. Come with your SQL and SQLite skills, or learn new ones as you go!
GRDB Usage
import GRDB // 1. Open a database connection let dbQueue = try DatabaseQueue(path: "/path/to/database.sqlite") // 2. Define the database schema try dbQueue.write { db in try db.create(table: "player") { t in t.primaryKey("id", .text) t.column("name", .text).notNull() t.column("score", .integer).notNull() } } // 3. Define a record type struct Player: Codable, FetchableRecord, PersistableRecord { var id: String var name: String var score: Int } // 4. Write and read in the database try dbQueue.write { db in try Player(id: "1", name: "Arthur", score: 100).insert(db) try Player(id: "2", name: "Barbara", score: 1000).insert(db) } let players: [Player] = try dbQueue.read { db in
Documentation
GRDB runs on top of SQLite: you should get familiar with the SQLite FAQ. For general and detailed information, jump to the SQLite Documentation.
Demo Applications & Frequently Asked Questions
- Demo Applications: Three flavors: vanilla UIKit, Combine + SwiftUI, and Async/Await + SwiftUI.
- FAQ
Reference
Getting Started
- Installation
- Database Connections: Connect to SQLite databases
SQLite and SQL
- SQLite API: The low-level SQLite API • executing updates • fetch queries • SQL Interpolation
Records and the Query Interface
- Records: Fetching and persistence methods for your custom structs and class hierarchies
- Query Interface: A swift way to generate SQL • create tables • requests • associations between record types
Application Tools
- Migrations: Transform your database as your application evolves.
- Full-Text Search: Perform efficient and customizable full-text searches.
- Database Observation: Observe database changes and transactions.
- Encryption: Encrypt your database with SQLCipher.
- Backup: Dump the content of a database to another.
- Interrupt a Database: Abort any pending database operation.
- Sharing a Database: How to share an SQLite database between multiple processes – recommendations for App Group containers, App Extensions, App Sandbox, and file coordination.
Good to Know
- Concurrency: How to access databases in a multi-threaded application.
- SwiftUI: Access and observe the database from your SwiftUI views.
- Combine: Access and observe the database with Combine publishers.
- Avoiding SQL Injection
- Error Handling
- Unicode
- Memory Management
- Data Protection
- 💡 Migrating From GRDB 5 to GRDB 6
- 💡 Why Adopt GRDB?
- 💡 Recommended Practices for Designing Record Types
