Github url


by stephencelis

stephencelis /SQLite.swift

A type-safe, Swift-language layer over SQLite3.

7.0K Stars 1.2K Forks Last release: about 1 year ago (0.12.2) MIT License 860 Commits 15 Releases

Available items

No Items, yet!

The developer of this repository has not created any items for sale yet. Need a bug fixed? Help with integration? A different license? Create a request here:


Build Status CocoaPods Version Swift5 compatible Platform Carthage compatible Join the chat at

A type-safe, Swift-language layer over SQLite3.

SQLite.swift provides compile-time confidence in SQL statement syntax and intent.


  • A pure-Swift interface
  • A type-safe, optional-aware SQL expression builder
  • A flexible, chainable, lazy-executing query layer
  • Automatically-typed data access
  • A lightweight, uncomplicated query and parameter binding interface
  • Developer-friendly error handling and debugging
  • Full-text search support
  • Well-documented
  • Extensively tested
  • SQLCipher support via CocoaPods
  • Active support atStackOverflow, and Gitter Chat Room(experimental)


import SQLite let db = try Connection("path/to/db.sqlite3") let users = Table("users") let id = Expression<int64>("id")
let name = Expression<string>("name")
let email = Expression<string>("email")

try { t in
    t.column(id, primaryKey: true)
    t.column(email, unique: true)
// CREATE TABLE "users" (
// "name" TEXT,
// )

let insert = users.insert(name 
<p>SQLite.swift also works as a lightweight, Swift-friendly wrapper over the C
<pre class="swift">let stmt = try db.prepare("INSERT INTO users (email) VALUES (?)")
for email in ["[email protected]", "[email protected]"] {

db.totalChanges // 3
db.changes // 1
db.lastInsertRowid // 3

for row in try db.prepare("SELECT id, email FROM users") {
    print("id: \(row[0]), email: \(row[1])")
    // id: Optional(2), email: Optional("[email protected]")
    // id: Optional(3), email: Optional("[email protected]")

try db.scalar("SELECT count(*) FROM users") // 2
<p><a href="">Read the documentation</a> or explore more,
interactively, from the Xcode project’s playground.</p>

<p><img src="[email protected]" alt="SQLite.playground Screen Shot"></p>

<p>For a more comprehensive example, see
<a href="">this article</a>
and the <a href="">companion repository</a>.</p>


<p><em>Note:</em> Version 0.12 requires Swift 5 (and <a href="">Xcode</a> 10.2) or greater. Version 0.11.6 requires Swift 4.2 (and <a href="">Xcode</a> 10.1) or greater.</p>


<p><a href="">Carthage</a> is a simple, decentralized dependency manager for Cocoa. To
install SQLite.swift with Carthage:</p>

<li><p>Make sure Carthage is <a href="">installed</a>.</p></li>
<p>Update your Cartfile to include the following:</p>
<pre class="ruby">github "stephencelis/SQLite.swift" ~&gt; 0.12.0
<p>Run </p>
<pre class="">carthage update</pre> and
<a href="">add the appropriate framework</a>.</li>


<p><a href="">CocoaPods</a> is a dependency manager for Cocoa projects. To install
SQLite.swift with CocoaPods:</p>

<p>Make sure CocoaPods is <a href="">installed</a>. (SQLite.swift
requires version 1.6.1 or greater.)</p>
<pre class="sh"># Using the default Ruby install will require you to use sudo when
# installing and updating gems.
[sudo] gem install cocoapods
<p>Update your Podfile to include the following:</p>
<pre class="ruby">use_frameworks!

target 'YourAppTargetName' do
    pod 'SQLite.swift', '~&gt; 0.12.0'
<p>Run </p>
<pre class="">pod install --repo-update</pre>.</li>

<h3>Swift Package Manager</h3>

<p>The <a href="">Swift Package Manager</a> is a tool for managing the distribution of
Swift code.</p>

<li>Add the following to your <pre class="">Package.swift</pre> file:</li>
<pre class="swift"> dependencies: [
      .package(url: "", from: "0.12.0")
<li>Build your project:</li>
<pre class="sh"> $ swift build

<p>To install SQLite.swift as an Xcode sub-project:</p>

<p>Drag the <strong>SQLite.xcodeproj</strong> file into your own project.
(<a href="">Submodule</a>, clone, or <a href="">download</a> the project first.)</p>

<p><img src="[email protected]" alt="Installation Screen Shot"></p>
<li><p>In your target’s <strong>General</strong> tab, click the <strong>+</strong> button under <strong>Linked
Frameworks and Libraries</strong>.</p></li>
<li><p>Select the appropriate <strong>SQLite.framework</strong> for your platform.</p></li>

<p>Some additional steps are required to install the application on an actual

<li><p>In the <strong>General</strong> tab, click the <strong>+</strong> button under <strong>Embedded
<li><p>Select the appropriate <strong>SQLite.framework</strong> for your platform.</p></li>


<p><a href="">See the planning document</a> for a roadmap and existing feature requests.</p>

<p><a href="">Read the contributing guidelines</a>. The <em>TL;DR</em> (but please; <em>R</em>):</p>

<li>Need <strong>help</strong> or have a <strong>general question</strong>? <a href="">Ask on Stack
Overflow</a> (tag <pre class="">sqlite.swift</pre>).</li>
<li>Found a <strong>bug</strong> or have a <strong>feature request</strong>? <a href="">Open an issue</a>.</li>
<li>Want to <strong>contribute</strong>? <a href="">Submit a pull request</a>.</li>


<a href="mailto:[email protected]">Stephen Celis</a>
(<a href="">@stephencelis</a>)</li>


<p>SQLite.swift is available under the MIT license. See <a href="">the LICENSE
file</a> for more information.</p>


<p>These projects enhance or use SQLite.swift:</p>

<a href="">SQLiteMigrationManager.swift</a> (inspired by
<a href="">FMDBMigrationManager</a>)</li>


<p>Looking for something else? Try another Swift wrapper (or <a href="">FMDB</a>):</p>

<li><a href="">Camembert</a></li>
<li><a href="">GRDB</a></li>
<li><a href="">SQLiteDB</a></li>
<li><a href="">Squeal</a></li>
<li><a href="">SwiftData</a></li>
<li><a href="">SwiftSQLite</a></li>

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.