I'm using TouchDB on an app to synchronize data with a CouchDB server on the cloud.
Everything is working fine, but I need to now deploy a preloaded version of the app with the app bundle, so the user doesn't have to download MBs of static data.
What's the best way of doing this? I'm thinking of just including the TouchDB directory with the database and the attachments on my project, and before I initialize the TouchDB database I check if it exists under the "Application Support" database and if not I copy it in my code.
Is this the correct approach?
You can include the database and attachments directory in your application bundle, then use
-(BOOL) replaceWithDatabaseFile: (NSString*)databasePath
withAttachments: (NSString*)attachmentsPath
error: (NSError**)outError;
https://github.com/couchbaselabs/TouchDB-iOS/blob/master/Source/TD_Database.h#L87
It looks like this does a few sanity checks before doing just what you were planning:
https://github.com/couchbaselabs/TouchDB-iOS/blob/master/Source/TD_Database.m#L91
However, it does mean that you don't have to keep your copying code in sync with where the database keeps its files.