mirror of
https://github.com/JohnEstropia/CoreStore.git
synced 2026-01-11 20:00:30 +01:00
Delete improvement when clearing the database #384
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @alinpetrus on GitHub (Mar 8, 2022).
We are using CoreStore and while we love it, there is one thing that is causing us a bit of trouble. When wanting to clear the whole database, we need to go through all the entities and do calls to deleteAll for each entity.
For large datasets this is fairly time consuming.
I am wondering if we could have something which is faster like using NSBatchDeleteRequest or a call to destroyPersistentStore on each store and recreating them afterwards.
@JohnEstropia commented on GitHub (Mar 9, 2022):
@alinpetrus Thanks. Should be simple enough to expose a safe method for it (since
cs_eraseStorageAndWait()already exists for the purpose of migrations). The hard part is ensuring that the existing observers are notified of the deletions. I'll try to push a prototype intodevelopthis weekend and let you play with it before we merge it tomain.In the mean time, if you can ensure that all references to the
DataStackcan be initialized, you can just replace yourDataStackwith a new one, delete the files related to the oldSQLiteStore().fileURL, and re-add theSQLiteStoreto the newDataStack. I have two projects that does this safely, but yeah we should have a supported safe way to remove stores in the API.