ios - GRDB swift 中的 DatabaseConnecton 问题

标签 ios swift grdb

我想在我的 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/

相关文章:

sqlite - GRDB.swift 使用 swift 3 请求而不通过模型[完成]

swift - 使用 GRDB,使用原始 sql 但以方便的形式使用结果?

ios - 在 ios6 的导航栏上放置自定义按钮不起作用

ios - 带有圆角的 UITableViewCell 上未显示删除按钮

android - Xamarin 的 IS Firebase 支持

swift - 在 Xamarin 中使用 Swift 库

iphone - 我应该单独制作 UIViewController 只是因为单行布局不同

Swift 编译器 2.1.1 永远卡在字典上

ios - iPhone - 检测触摸并取消触摸?

ios - 通过没有 Storyboard的函数从另一个类执行 Segue