mirror of
https://github.com/JohnEstropia/CoreStore.git
synced 2026-03-25 10:51:59 +01:00
WIP: make fetching methods throwable
This commit is contained in:
@@ -139,29 +139,40 @@ public struct From<D: DynamicObject> {
|
||||
self.findPersistentStores = findPersistentStores
|
||||
}
|
||||
|
||||
internal func applyToFetchRequest<ResultType>(_ fetchRequest: NSFetchRequest<ResultType>, context: NSManagedObjectContext, applyAffectedStores: Bool = true) -> Bool {
|
||||
internal func applyToFetchRequest<U>(_ fetchRequest: NSFetchRequest<U>, context: NSManagedObjectContext, applyAffectedStores: Bool = true) throws {
|
||||
|
||||
fetchRequest.entity = context.parentStack!.entityDescription(for: EntityIdentifier(self.entityClass))!
|
||||
guard applyAffectedStores else {
|
||||
|
||||
return true
|
||||
return
|
||||
}
|
||||
if self.applyAffectedStoresForFetchedRequest(fetchRequest, context: context) {
|
||||
|
||||
return true
|
||||
do {
|
||||
|
||||
try self.applyAffectedStoresForFetchedRequest(fetchRequest, context: context)
|
||||
}
|
||||
catch let error as CoreStoreError {
|
||||
|
||||
CoreStore.log(
|
||||
error,
|
||||
"Attempted to perform a fetch but could not find any persistent store for the entity \(cs_typeName(fetchRequest.entityName))"
|
||||
)
|
||||
throw error
|
||||
}
|
||||
catch {
|
||||
|
||||
throw error
|
||||
}
|
||||
CoreStore.log(
|
||||
.warning,
|
||||
message: "Attempted to perform a fetch but could not find any persistent store for the entity \(cs_typeName(fetchRequest.entityName))"
|
||||
)
|
||||
return false
|
||||
}
|
||||
|
||||
internal func applyAffectedStoresForFetchedRequest<U>(_ fetchRequest: NSFetchRequest<U>, context: NSManagedObjectContext) -> Bool {
|
||||
internal func applyAffectedStoresForFetchedRequest<U>(_ fetchRequest: NSFetchRequest<U>, context: NSManagedObjectContext) throws {
|
||||
|
||||
let stores = self.findPersistentStores(context)
|
||||
fetchRequest.affectedStores = stores
|
||||
return stores?.isEmpty == false
|
||||
if stores?.isEmpty == false {
|
||||
|
||||
return
|
||||
}
|
||||
throw CoreStoreError.persistentStoreNotFound(entity: self.entityClass)
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user