Latest 1.0.0
License MIT
Platforms ios 10.0

Simple Sqlite3 wrapper for Swift 4, because sometimes you just want to write queries and get the results without any hassle.

SQLiteQuery provides an easy-to-use DataTable class for query results.


  • Easy to use and understand Swift interface.
  • No need to manage OpaquePointer statements, SQLiteQuery manages query statements for you.
  • Extend SQLiteConnector to create classes with interfaces specific to the data they manage.
  • Well-documented methods.
  • DataTable class for easy access to results from a SELECT query.

In The Works

  • Support for Blobs.
  • Mapping of query results to a custom Class so that results can be an Array of custom objects.
  • Better/Cleaner test cases.


//setup a database connection by passing name of database file to open or create
//database file is created in the user's document directory
var database = SQLiteConnector(databaseName: "database_file_name")

//to use the database connection, open it

//run your queries

//get the last generated row id from an INSERT statement
let accountID = database.lastRowId()

//get the total number of rows changed ( on UPDATE or DELETE )
let totalChangedRows = database.totalChanges()

//remove parameters and finalize the statement

//close the connection

Using the execute(String) and execute() methods for INSERT, UPDATE, DELETE, CREATE

//use to create a table
try! database.execute("create table account(account_id integer primary key, name text, description text)")

//use to insert data
try! database.execute("insert into account(name, description) values('john', 'marketing and sales')")
try! database.execute("insert into account(name, description) values('lisa', 'development')")

//use parameters
database.setParameter(name: "accountName", value: "Lex")
database.setParameter(name: "accountDesc", value: "Print Designer")

try! database.execute("insert into account(name, description) values(@accountName, @accountDesc)")

//change the parameters for a new entry
database.setParameter(name: "accountName", value: "Todd")
database.setParameter(name: "accountDesc", value: "Graphic Designer")

//use execute() to re-execute the last statement( this method doesn't re-compile the statement )
try! database.execute()

//clear the parameters ( this needs to be done before executing a statement with different parameters )

Using the executeScalar(String) and executeScalar methods for SELECT statements that return a single value

database.setParameter(name: "accountName", value: "john")
let johnAccountID = try! database.executeScalar("select account_id from account where [email protected]") as! Int

//use executeScalar() so the statement isn't re-compiled
database.setParameter(name: "accountName", value: "lisa")
let lisaAccountID = try! database.executeScalar() as! Int


let totalAccounts = try! database.executeScalar("select count(*) from account") as! Int

Using the executeDataTable(String) and executeDataTable() methods for SELECT statements that return data sets

//returns a datatable where each row has an element for each column in the select list
let table = try! database.executeDataTable("select * from account")

//access individual rows and their column data
let firstName = table.rows[0]["name"] as! String

//loop through all the rows
for row in table.rows {
  print(row["name"] as! String)
  print(row["description"] as! String)


Latest podspec

    "name": "SQLiteQuery",
    "version": "1.0.0",
    "summary": "An easy to use SQLite wrapper for Swift 4",
    "description": "Write SQL queries and get results. This framework is great for developers who like to write their own SQL queries.",
    "homepage": "",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    "authors": {
        "Gail Sparks": "[email protected]"
    "source": {
        "git": "",
        "tag": "1.0.0"
    "platforms": {
        "ios": "10.0"
    "source_files": [
    "pushed_with_swift_version": "4.0"

Pin It on Pinterest

Share This