GRDB 中的数据库连接问题 swift

DatabaseConnecton issue in GRDB swift

我想在我的 iOS 应用程序中使用 SQLite 数据库,并且有不同的框架可用。所以我目前的重点是 GRDB and I have successfully created, inserted values, and received back with SQL commands as shown here.

但是,应用程序关闭后,我将如何访问同一个 DataBaseQueue 以及我的数据库的固定路径应该是什么?

import GRDB

// Open a simple database connection

if let dbQueue = try DatabaseQueue(path: "what should be the correct path ")!= nil{
    setupDatabase()
}
else
{
    dbQueue = DatabaseQueue()
}

GRDB FAQ 回答了您的问题:

How do I create a database in my application?

The database has to be stored in a valid place where it can be created and modified. For example, in the Application Support directory:

let databaseURL = try FileManager.default
    .url(for: .applicationSupportDirectory, in: .userDomainMask, appropriateFor: nil, create: true)
    .appendingPathComponent("db.sqlite")
let dbQueue = try DatabaseQueue(path: databaseURL.path)