@@ -97,6 +97,44 @@ typedef id __nonnull (^YapDatabaseDeserializer)(NSString *collection, NSString *
9797typedef id __nonnull (^YapDatabasePreSanitizer)(NSString *collection, NSString *key, id obj);
9898typedef void (^YapDatabasePostSanitizer)(NSString *collection, NSString *key, id obj);
9999
100+ /* *
101+ * This notification is posted when a YapDatabase instance is deallocated,
102+ * and has thus closed all references to the underlying sqlite files.
103+ *
104+ * If you intend to delete the sqlite file(s) from disk,
105+ * it's recommended you use this notification as a hook to do so.
106+ *
107+ * More info:
108+ * The YapDatabase class itself is just a retainer for the filepath, blocks, config, etc.
109+ * And YapDatabaseConnection(s) open a sqlite connection to the database file,
110+ * and rely on the blocks & config in the parent YapDatabase class.
111+ * Thus a YapDatabaseConnection instance purposely retains the YapDatabase instance.
112+ * This means that in order to fully close all references to the underlying sqlite file(s),
113+ * you need to deallocate YapDatabase and all associated YapDatabaseConnections.
114+ * While this may be simple in concept, it's generally difficult to know exactly when all
115+ * the instances have been deallocated. Especially when there may be a bunch of asynchronous operations going.
116+ *
117+ * Therefore the best approach is to do the following:
118+ * - destroy your YapDatabase instance (set it to nil)
119+ * - destroy all YapDatabaseConnection instances
120+ * - wait for YapDatabaseClosedNotification
121+ * - use notification as hook to delete all associated sqlite files from disk
122+ *
123+ * The userInfo dictionary will look like this:
124+ * @{
125+ * YapDatabasePathKey : <NSString of full filePath to db.sqlite file>,
126+ * YapDatabasePathWalKey : <NSString of full filePath to db.sqlite-wal file>,
127+ * YapDatabasePathShmKey : <NSString of full filePath to db.sqlite-shm file>,
128+ * }
129+ *
130+ * This notification is always posted to the main thread.
131+ **/
132+ extern NSString *const YapDatabaseClosedNotification;
133+
134+ extern NSString *const YapDatabasePathKey;
135+ extern NSString *const YapDatabasePathWalKey;
136+ extern NSString *const YapDatabasePathShmKey;
137+
100138/* *
101139 * This notification is posted following a readwrite transaction where the database was modified.
102140 *
@@ -108,10 +146,10 @@ typedef void (^YapDatabasePostSanitizer)(NSString *collection, NSString *key, id
108146 *
109147 * The userInfo dictionary will look something like this:
110148 * @{
111- * YapDatabaseSnapshotKey = <NSNumber of snapshot, incremented per read-write transaction w/modification>,
112- * YapDatabaseConnectionKey = <YapDatabaseConnection instance that made the modification(s)>,
113- * YapDatabaseExtensionsKey = <NSDictionary with individual changeset info per extension>,
114- * YapDatabaseCustomKey = <Optional object associated with this change, set by you>,
149+ * YapDatabaseSnapshotKey : <NSNumber of snapshot, incremented per read-write transaction w/modification>,
150+ * YapDatabaseConnectionKey : <YapDatabaseConnection instance that made the modification(s)>,
151+ * YapDatabaseExtensionsKey : <NSDictionary with individual changeset info per extension>,
152+ * YapDatabaseCustomKey : <Optional object associated with this change, set by you>,
115153 * }
116154 *
117155 * This notification is always posted to the main thread.
0 commit comments