In GRDB I can create read-only database connections with
try dbPool.read { db in
I can create read-write database connections with
try dbPool.write { db in
In each case I can call a function from within the closure using db as an argument. In GRDB read-only database connections can run in parallel in different threads. Write database connections block the database.
I have a pattern I would like to use in some functions:
- Select a record filtered on some attributes.
- If a record is found, return it.
- If no record is found, create a default placeholder record with those attributes.
- If the db is read-write, save the default placeholder and return it.
- If the db is read-only, just return the placeholder
Is there a way to determine if the db is read-only? Looking through the reference documentation at http://groue.github.io/GRDB.swift/docs/4.1/Classes/Database.html, I don't see a simple way to determine this aside from error handling.
I could just attempt to save in the function and catch the error if the db is read-only.