I'm trying to retrieve a count of records in a table using SQLite.swift and Swift in a Cocoa macOS application. According to the README, this can be achieved using the following:
let users = Table("users")
...
let count = try db.scalar(users.count)
However, when this code is executed (from a button click event handler), the following exception is thrown:
Fatal error: 'try!' expression unexpectedly raised an error: unrecognized token: ":" (code: 1): file...
The offending code is the db
access line below. The db
object is assigned with a Connection
object returned from a separate Database
struct function when the view loads. I believe this is valid and unrelated as other areas of code are using the same method to open connections to the database successfully.
let login = Login()
var db : Connection?
...
let count = try! db?.scalar(login.table.count)
Here's the query expression it produces. In text, this appears to be SELECT count(_:)(*) FROM login
.
However, interestingly, if I use the following line, the correct result is returned.
let count = try! db?.scalar(“SELECT COUNT(*) FROM login”)
The model for this Login
object is:
import SQLite
public struct Login {
let table = Table("login")
// Bunch of properties for various record fields
init() {}
}
Any and all help would be appreciated. Thanks in advance!