I'm trying to convert several of my apps to use GRDB.swift. Does anybody have or know where I can find a file to get me started? I've read over most of the GRDB docs but I'm not getting it. Below is a sample scenario.
This I was able to convert from SQLite.sift
class Database
{
static let shared = Database()
public let databaseConnection: DatabaseQueue?
private init()
{
do
{
let fileUrl = try FileManager.default.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: false).appendingPathComponent("MyDaatbase.sqlite")
// GRDB
let databaseConnection = try DatabaseQueue(path: fileUrl.path)
self.databaseConnection = databaseConnection
} catch {
databaseConnection = nil
let nserror = error as NSError
print("Cannot connect to Database. Error is: (nserror), (nserror.userInfo)")
}
}
}
Could someone please convert this to GRDB to help me get started?
static func isAnimation() -> Bool
{
let theTable = Table("Settings")
let theColumn = Expression<String>("AnimateNav")
var theStatus = false
do {
for theAnswer in try Database.shared.databaseConnection!.prepare(theTable.select(theColumn)) {
//print(theAnswer[theColumn])
let theStatusText = (theAnswer[theColumn])
theStatus = theStatusText == "true" ? true : false
}
} catch {
print("Getting the isAnimation Status failed! Error: (error)")
}
return theStatus
}
question from:
https://stackoverflow.com/questions/65545884/converting-app-from-sqlite-swift-to-grdb-swift 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…