gpt4 book ai didi

ios - GRDB swift 中的 DatabaseConnecton 问题

转载 作者:行者123 更新时间:2023-11-30 12:00:43 26 4
gpt4 key购买 nike

我想在我的 iOS 应用程序中使用 SQLite 数据库,并且有不同的框架可用。所以我目前的重点是GRDB我已成功创建、插入值,并使用 SQL 命令接收返回值,如图 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)

关于ios - GRDB swift 中的 DatabaseConnecton 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47275022/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com