Latest 1.2.0
License MIT
Platforms ios 9.0, tvos 9.0, osx 10.10, watchos 3.0

Squeal, a Swift interface to SQLite

Squeal provides access to SQLite databases in Swift. Its goal is to provide a
simple and straight-forward base API, allowing developers to build on top in ways that make sense for their apps. The
API provides direct SQL access, as well as a complete set of helpers to reduce SQL drudgery. It’s not a goal of this
project to hide SQL from the developer, or to provide a generic object-mapping on top of SQLite.


  • Small, straightforward Swift interface for accessing SQLite databases via SQL.
  • Helper methods for most common types of SQL statements.
  • Easy database schema versioning and migration DSL.
  • Simple DatabasePool implementation for concurrent access to a database.

Basic Usage

import Squeal

let db = Database()

// Create:
try db.createTable("contacts", definitions: [
    "name TEXT",
    "email TEXT NOT NULL"

// Insert:
let contactId = try db.insertInto(
    values: [
        "name": "Amelia Grey",
        "email": "[email protected]"

// Select:
struct Contact {
    let id:Int
    let name:String?
    let email:String

    init(row:Statement) throws {
        id = row.intValue("id") ?? 0
        name = row.stringValue("name")
        email = row.stringValue("email") ?? ""

let contacts:[Contact] = try db.selectFrom(
    whereExpr:"name IS NOT NULL",
    block: Contact.init

// Count:
let numberOfContacts = try db.countFrom("contacts")

The above example can be found in Squeal.playground to allow further exploration of Squeal’s interface.


Any non-trivial app will need to change its database schema as features are added or updated. Unfortunately, SQLite
provides only minimal support for updating a database’s schema. Things like removing a column or removing a NON NULL
require the entire database to be re-created with the new schema.

Squeal makes migrations easy by including a Schema class with a simple DSL for declaring your database migrations.
Once defined, the Schema can be used to migrate your database to the latest version.

Here’s an example:

import Squeal

// Define a Schema:
let AppSchema = Schema(identifier:"contacts") { schema in
    // Version 1:
    schema.version(1) { v1 in
        // Create a Table:
        v1.createTable("contacts") { contacts in
            contacts.column("name", type:.Text)
            contacts.column("email", type:.Text, constraints:["NOT NULL"])

        // Add an index
            on: "contacts",
            columns: [ "email" ]

    // Version 2:
    schema.version(2) { v2 in        
        // Arbitrary SQL:
        v2.execute { db in
            try db.deleteFrom("contacts", whereExpr: "name IS NULL")
        // Tables can be altered in many ways.
        v2.alterTable("contacts") { contacts in
                setConstraints: [ "NOT NULL" ]
            contacts.addColumn("url", type: .Text)            

let db = Database()

// Migrate to the latest version:
let didMigrate = try AppSchema.migrate(db)

// Get the database version:
let migratedVersion = try db.queryUserVersionNumber()

// Reset the database:
try AppSchema.migrate(db, toVersion: 0)

The above example can be found in Migrations.playground.


Squeal can be installed via Carthage or CocoaPods.


To install using Carthage, simply add the following line to your Cartfile:

github "nerdyc/Squeal"


To install using Carthage, simply add the following to the appropriate target in your Podfile:

pod "Squeal"


Squeal is released under the MIT License. Details are in the LICENSE.txt file in the project.


Contributions and suggestions are very welcome! No contribution is too small. Squeal (like Swift) is still evolving and feedback from the community is appreciated. Open an Issue, or submit a pull request!

The main requirement is for new code to be tested. Nobody appreciates bugs in their database.

Latest podspec

    "name": "Squeal",
    "version": "1.2.0",
    "summary": "A Swift wrapper for SQLite databases",
    "description": "Squeal provides access to SQLite databases in Swift. Its goal is to bensimple and straight-forward, without much magic.nnSqueal provides some helpers to generate and execute the most common SQL nstatements, and take the drudgery out of generating these yourself. nHowever, it's not a goal of this project to hide SQL from the developer, or nto provide a generic object-mapping on top of SQLite.",
    "homepage": "",
    "license": {
        "type": "MIT",
        "file": "LICENSE.txt"
    "authors": {
        "Christian Niles": "[email protected]"
    "social_media_url": "",
    "platforms": {
        "ios": "9.0",
        "tvos": "9.0",
        "osx": "10.10",
        "watchos": "3.0"
    "source": {
        "git": "",
        "tag": "v1.2.0"
    "source_files": "Sources/**/*.swift",
    "module_name": "Squeal",
    "libraries": "sqlite3",
    "preserve_paths": "Clibsqlite3/**/*",
    "pod_target_xcconfig": {
        "SWIFT_INCLUDE_PATHS[sdk=macosx*]": "$(PODS_TARGET_SRCROOT)/Clibsqlite3/macOS/**",
        "SWIFT_INCLUDE_PATHS[sdk=iphoneos*]": "$(PODS_TARGET_SRCROOT)/Clibsqlite3/iOS/**",
        "SWIFT_INCLUDE_PATHS[sdk=iphonesimulator*]": "$(PODS_TARGET_SRCROOT)/Clibsqlite3/iOS-Simulator/**",
        "SWIFT_INCLUDE_PATHS[sdk=appletvos*]": "$(PODS_TARGET_SRCROOT)/Clibsqlite3/tvOS/**",
        "SWIFT_INCLUDE_PATHS[sdk=appletvsimulator*]": "$(PODS_TARGET_SRCROOT)/Clibsqlite3/tvOS-Simulator/**",
        "SWIFT_INCLUDE_PATHS[sdk=watchos*]": "$(PODS_TARGET_SRCROOT)/Clibsqlite3/watchOS/**",
        "SWIFT_INCLUDE_PATHS[sdk=watchsimulator*]": "$(PODS_TARGET_SRCROOT)/Clibsqlite3/watchOS-Simulator/**"
    "pushed_with_swift_version": "3.0"

Pin It on Pinterest

Share This