
SQLite.swift
A Swift library that wraps SQLite with type-safe queries and no raw SQL strings required.
- Stars
- 10.2k
- Forks
- 1.6k
- Licence
- MIT
- Language
- Swift
- Last update
- 12 days ago
- Type
- Library
What it is
SQLite.swift is a Swift library that sits on top of SQLite3, the small database engine built into many apps and devices. Instead of writing SQL as plain text, you describe tables and queries using Swift code, and the compiler can catch some mistakes before the app runs. It also lets you run raw SQL statements directly when you need to.
- Create tables, insert rows, and query them with a typed Swift expression builder
- Run parameterized raw SQL statements through a Swift-friendly wrapper
- Use full-text search and inspect or migrate the database schema
- Configure WAL journal mode with Connection(_, journalMode: .wal)
Great for
- Swift developers building iOS, macOS, or other Apple-platform apps that store data locally in SQLite
- Developers who want compile-time checks on their database queries
- Teams that prefer Swift Package Manager for dependency management
- Developers who need SQLCipher encryption support via Swift Package Manager
Not ideal for
- Developers who want an async-first or ORM-style API; the README describes a query builder and raw-SQL wrapper, not that style
- Projects that need full Linux support without caveats, since the README says Linux works only with some limitations
- Anyone who wants a non-Swift database client
How to get it
- 1
Install with a package manager
You'll need: Swift toolchain with Swift Package Manager · Xcode for Apple-platform projects (manual install path)
Add to Package.swift dependencies
.package(url: "https://github.com/stephencelis/SQLite.swift.git", from: "0.17.0")Build the project
swift build - 2
Run it
- Add the SQLite.swift dependency to your Package.swift file
- Run swift build to fetch and compile the package
- Import SQLite in a Swift file and open a database with Connection("path/to/db.sqlite3")
- Create a table with db.run(users.create { ... }) and insert a row to confirm it works
- 3
Get the most out of it
- Use prepareRowIterator(_:) instead of prepare(_:) when you need to handle errors during row iteration
- Write SQLite.Expression instead of Expression to avoid name clashes when using SwiftUI
- Enable WAL mode with Connection(_, journalMode: .wal) or enableWAL() for better journaling behavior
- Explore the Xcode playground included in the repository to try queries interactively
- Use the Documentation/Index.md guide for full-text search and schema querying
Downloads
Strengths
- Type-safe, optional-aware query builder that reduces raw SQL string errors
- Installs through Swift Package Manager with a single dependency line
- MIT licensed with documentation and a playground in the project
Trade-offs
- Iterating prepare() results crashes on errors unless you use prepareRowIterator(_:) instead, as the README warns
- Linux support is described as limited and the Gitter chat is marked experimental
- Latest release is 0.17.0 and the README does not state a minimum Swift or platform version
How it compares
| Project | Stars | Type | Level | Updated | Best for |
|---|---|---|---|---|---|
| SQLite.swift (this) | 10.2k | Library | intermediate | 12 days ago | Swift developers building iOS, macOS, or other Apple-platform apps that store data locally in SQLite |
| kysely | 14.3k | Library | intermediate | 4 days ago | TypeScript developers who want SQL control without losing compile-time type checks |
| Alamofire | 42.4k | Library | intermediate | 5 days ago | Swift developers building iOS or macOS apps that call web APIs |
| typeorm | 36.7k | Library | intermediate | 8 days ago | Node.js or TypeScript developers building apps backed by a relational database |
| sequelize | 30.3k | Library | intermediate | 5 days ago | Node.js backend developers who use a relational SQL database |
| SDWebImage | 25.6k | Library | intermediate | 7 months ago | iOS or macOS app developers who need to show remote images in lists or grids |
Stats synced from GitHub. The assessment above was drafted with AI from the project's README on 2026-10-29 and may miss recent changes — check the README before relying on a command. MIT licence: free to use, modify and distribute, including commercially, as long as you keep the copyright notice.