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.

  • 2
    Please see the comment here: https://github.com/stephencelis/SQLite.swift/issues/199#issuecomment-140889578 Also quickly look over the swift-2 branch's README and documentation for other updates. – stephencelis Sep 18 '15 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 – Paolo Bernardini Sep 18 '15 at 14:37
  • You need to wrap that `try` in a `do`-`catch` block. Read up on error handling in Swift 2 for more. – stephencelis Sep 20 '15 at 00:02
  • Thanks @stephencelis. Please add your comment as answer in this case it will be more prominent. – Muhammad Saifullah Oct 20 '15 at 06:57

1 Answers1

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.

Kingxlayer
  • 119
  • 5