5

I am writing an NSDocument based application that has an SQLite database that I wish to tag along in the document bundle. It consists of some number of tables, with the schema for each table being a timestamp and a value. This database will start out small, but could grow to a sizable amount over time. The application is updating the database "behind NSDocument's back."

What I have attempted to do thus far is override the writeToURL:ofType:error: method, which can get passed some convoluted URL like:

file://localhost/private/var/folders/mr/l1z6gdls0fb3t28m3z1bz6lw0000gn/T/TemporaryItems/(A%20Document%20Being%20Saved%20By%MyApp%2031)/Untitled.wsdoc

At this point I am forced, if you will, to use an in-memory database, then suck up the entire contents of that database into an NSFileWrapper. It works, but it doesn't scale well. Doing his each time someone presses Command-S (or worse yet, I turn on autosaving) could be a very expensive operation if the database is huge, say 200-300MB or more (which is not out of the realm of possibility for this application).

So I'm wondering: is it possible to manage an SQLite file outside of the purview of NSDocument while still having it reside IN the document bundle so that the database can exist within the bundle as it is moved/copied?

ronalchn
  • 12,225
  • 10
  • 51
  • 61
  • Did you ever find an answer? – I’m about to attempt exactly the same thing, for almost exactly the same reasons. – DouglasHeriot Feb 16 '13 at 10:36
  • I'm just starting to work on this now too, but since nobody has commented in the past few years, I'm guessing the OP either gave up or found a solution but didn't resolve his question. I'd love to know what the drawbacks are before I begin down a possible fruitless path. I know that NSPersistentDocument (and UIManagedDocument) manages an SQLite file. Just not sure if there's any sorcery going on. – Tap Forms Jun 01 '15 at 23:57
  • Oh, and I don't want to use NSPersistentDocument and UIManagedDocument because I don't want to use CoreData. I'm trying to do it with CouchBase. – Tap Forms Jun 01 '15 at 23:58
  • Ok, I’m trying this with Realm. Did anyone succeed? – Jay Lee May 12 '21 at 11:09

0 Answers0