Is there a GRDB for macOS

Is there something like GRDB for macOS development?


Looking at the GRDB documentation, it seems like it supports MacOS 10.10, 10.11, 10.12, ..., 10.15. I would assume it will be ported over to MacOS 11. There is a GRDBOSX target in the Xcode project/workspace

I see what you are saying. It does look like it supports macOS.
The following screen shot is what confused me. As you can see the platform mentioned don't include macOS. Although below low that in requirements it does have macOS 10.10+.

At any rate since it does appear to support macOS.... is there a demo of GRDB with a macOS target?

osx == macOS, the platform image just hasn't been updated with the new name.

I doubt the API is any different on macOS than iOS, so a demo wouldn't do much. Give sample code a shot and see what happens.

Thanks, I will... Also,I must confess I knew full well that OS X = macOS. I was just had tunnel vision.

So, I am following the following document:

Getting Started with GRDB

In trying to convert the IOS code at the top to OS X code at the bottom I not sure how to code
DataBaseManager class for OS X as well as the code to call the setup method.

Any help with this is appreciated.
Create new file called DataBaseManager.swift

*IOS code
import GRDB
var dbQueue: DatabaseQueue!
class DatabaseManager {
static func setup(for application: UIApplication) throws {
let databaseURL = try FileManager.default
.url(for: .applicationDirectory, in: .userDomainMask, appropriateFor: nil, create: true)
dbQueue = try DatabaseQueue(path: databaseURL.path)
dbQueue.setupMemoryManagement(in: application)
Call the setup method in your AppDelegate

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
try! DatabaseManager.setup(for: application)
return true

import Cocoa
import GRDB

var dbQueue: DatabaseQueue!

class DatabaseManager {
static func setup(for application: NSApplication) throws {

    let homeURL = FileManager.default.homeDirectoryForCurrentUser
    let desktopPath = "Desktop/"
    let databaseName = "Test.db3"
    let databaseURL = homeURL.appendingPathComponent(desktopPath + databaseName)
    print("Path: " + databaseURL.path)

 dbQueue = try DatabaseQueue(path: databaseURL.path)

// dbQueue.setupMemoryManagement(in: application)



class AppDelegate: NSObject, NSApplicationDelegate {

func applicationDidFinishLaunching(_ aNotification: Notification) {
    // Insert code here to initialize your application
 try! DatabaseManager.setup(for: application)

In your call to the setup call, use NSApp for the application. NSApp is the shared variable that refers to your main application object. Best to read the about NSApplication, NSApp, in the Apple documentation

I made the change and read the Apple Documentation. I now get the following error:

2020-07-13 14:35:50.945023-0500 PayMe[2382:98653] [logging-persist] os_unix.c:44152: (0) open(/Users/bsoule/Desktop/TestGRDB.db3) - Undefined error: 0

Fatal error: 'try!' expression unexpectedly raised an error: SQLite error 14: unable to open database file: file /Users/bsoule/Documents/Xcode/PayMe/PayMe/AppDelegate.swift, line 21

2020-07-13 14:36:15.392148-0500 PayMe[2382:98653] Fatal error: 'try!' expression unexpectedly raised an error: SQLite error 14: unable to open database file: fil

I have stepped through my program using debug/step into and can't see exactly where it is getting this error. Looking on the web it seems to be a general purpose error. Any ideas how to debug this error?

Also, get the following while running GRDBOSX tour playground?

warning: Tour.playground:130:9: warning: initialization of immutable value 'favoritePlaces' was never used; consider replacing with assignment to '_' or removing it
let favoritePlaces = try Place // [Place]


You likely need to enable disk access in the "Signing & Capabilities" tab of your app target in Xcode.

I still get the same error. I changed the following under sandbox group, it had read before:

Is this where you were referring to?

Sorry, I'm not sure. I suggest the Apple Developer Forums or StackOverflow for general questions like that.

Thanks, I try over there. I will post back when I get it resolved..

I opened a new thread for this issue.

New Thread

Are there any good examples or suggestions about how to integrate GRDB with a document-based application. I was thinking about integrating GRDB in my Document subclass but wasn't able to make use of the methods that read and write to a Data value type. In other words, I didn't know if I could nor if it would be good practice to create a GRDB database instance from a data value type in memory. Alternatively, I could override the methods that use URLs (file paths) to read and write to the file but didn't know which ones I would be interested in overriding. Are there any suggestions or good examples about how I can read and write to an SQLite database within a document-based application?

@Tessie, last time I wrote a NSDocument-based mac app with GRDB, I used an in-memory database, and used the backup method in order to read and write on the disk in a document bundle. These days I'd explore a temp db on disk, just to see how well it can go.

Anyway: the hardest part is understanding the Document apis, their goals and features, and building a plan around them that fits well in the OS, and well in your users' workflow and mental model. That is the real topic.

Whether you plug GRDB on top of it, or a JSON library does not change much. On Document apis, you'll find better help on the Apple Developer Forums or on Stack Overflow.

Mandatory warning: Core Data support for Undo and AppleScript is unmatched (almost free). For the best integration in macOS, you may consider using it in place of GRDB.

Terms of Service

Privacy Policy

Cookie Policy