0

I just upgraded to the branch of SQLite.swift for xCode 7 and Swift 2. Now along with a million other errors I am trying to correct I can't figure out what is the equivalent to the previous Database.userVersion? I know Database type has been replaced with the Connection type. But what do I check to know what version of schema changes a particular users has which I previous handled via the following code snippet:

private func migrate (){
    //dropTables()

    if db.userVersion == 0 {
        initializeDatabase()
        db.userVersion = 1
    }

    if db.userVersion == 1 {
        LogMsgSchema().createTable(con)
        db.userVersion = 2
    }

    if db.userVersion == 2 {
        CamerasSchema().updateTable(db, dbVersion: db.userVersion)
        PhotosSchema().updateTable(db, dbVersion: db.userVersion)
        db.userVersion = 3
    }

    if db.userVersion == 3 {
        CameraFeaturesSchema().createTable(db)
        db.userVersion = 4
    }
}
Wayne Fulcher
  • 741
  • 1
  • 11
  • 21
  • Please see this thread: https://github.com/stephencelis/SQLite.swift/issues/194 It'll give you an extension you can use in your project. – stephencelis Sep 24 '15 at 20:05

1 Answers1

0

This example from https://github.com/stephencelis/SQLite.swift/issues/194 shows how you can create an extension to do this with the latest SQLite.swift:

import SQLite

let db = try! Connection("foo.sqlite", readonly: false)
db.trace { print($0) }

extension Connection {
    public var userVersion: Int {
        get { return Int(scalar("PRAGMA user_version") as! Int64) }
        set { try! run("PRAGMA user_version = \(newValue)") }
    }
}

db.userVersion = 7
print(db.userVersion)
mm2001
  • 6,427
  • 5
  • 39
  • 37