1

Since I have updated to Xcode 7 and swift 2, I'm getting this errors:

No type named 'Query' in module 'SQLite' Use of undeclared type 'Database'

using this code:

let table:SQLite.Query

init(db:Database){

    table = db["BucketType"]
}

I'm using the swift2 branch of SQLite.swift, but it looks like my project, it can't find the reference SQLite.swift module. Also have import SQLite on every file I use SQLite.swift with. I've tried the manual integration and the cocoa pods, but with the same results.

It was working with Xcode 6.4.

4
  • 2
    Please see the comment here: github.com/stephencelis/SQLite.swift/issues/… Also quickly look over the swift-2 branch's README and documentation for other updates. Commented Sep 18, 2015 at 12:22
  • Thanks I got it. now I have this as per your example let _appDb = try Connection(dbPath.relativePath!) but get this error Errors thrown from here are not handled Commented Sep 18, 2015 at 14:37
  • You need to wrap that try in a do-catch block. Read up on error handling in Swift 2 for more. Commented Sep 20, 2015 at 0:02
  • Thanks @stephencelis. Please add your comment as answer in this case it will be more prominent. Commented Oct 20, 2015 at 6:57

1 Answer 1

3

I have something like this...

class DBHelper {

static let instance = DBHelper() // singleton

var db : Connection

init() {
    do {
        self.db = try Connection("\(Util.getDBPath())/db.sqlite3")
        createTablesIfNotExists()
    } catch {
        Logger.error("Could not create a connection to database")
    }
}

func createTablesIfNotExists() {

    // Logs

    let logs = Table(TLog.TABLE_NAME) // just the name of your table
    do {
        try db.run(logs.create(ifNotExists: true) { t in
                t.column(TLog.ID, primaryKey: true) // Expression<Int>("id")
                t.column(TLog.TS) // Expression<String>("ts")
                t.column(TLog.TAG) // Expression<String>("tag")
                t.column(TLog.TYPE) ...
                t.column(TLog.CONTENT) ...
        })
    } catch {
        Logger.error("Could not create table Logs")
    }

}

And.. Util.getDBPath would be...

import SystemConfiguration

class Util {

class func getDBPath() -> String {
    let path = NSSearchPathForDirectoriesInDomains(
        .DocumentDirectory, .UserDomainMask, true
    ).first

    return path!
}

}

Hope this help you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.