mirror of
https://github.com/JohnEstropia/CoreStore.git
synced 2026-01-16 14:06:53 +01:00
WIP
This commit is contained in:
@@ -37,6 +37,9 @@ public protocol SchemaMappingProvider {
|
||||
func createMappingModel() throws -> (mappingModel: NSMappingModel, migrationType: MigrationType)
|
||||
}
|
||||
|
||||
|
||||
// MARK: - EntityMappingProvider
|
||||
|
||||
public protocol EntityMappingProvider {
|
||||
|
||||
var source: (schema: DynamicSchema, entity: DynamicEntity) { get }
|
||||
@@ -46,33 +49,68 @@ public protocol EntityMappingProvider {
|
||||
}
|
||||
|
||||
|
||||
// MARK: - XcodeMappingModelProvider
|
||||
// MARK: - LightweightMappingModelProvider
|
||||
|
||||
open class XcodeMappingModelProvider<S: DynamicSchema, D: DynamicSchema>: SchemaMappingProvider {
|
||||
open class LightweightMappingModelProvider<SourceSchema: DynamicSchema, DestinationSchema: DynamicSchema>: SchemaMappingProvider {
|
||||
|
||||
private let mappingModelBundles: [Bundle]
|
||||
|
||||
public required init(source: SourceSchema, destination: DestinationSchema, mappingModelBundles: [Bundle] = Bundle.allBundles) {
|
||||
public required init(source: SourceSchema, destination: DestinationSchema) {
|
||||
|
||||
self.sourceSchema = source
|
||||
self.destinationSchema = destination
|
||||
self.mappingModelBundles = mappingModelBundles
|
||||
}
|
||||
|
||||
|
||||
// MARK: SchemaMappingProvider
|
||||
|
||||
public typealias SourceSchema = S
|
||||
public typealias DestinationSchema = D
|
||||
|
||||
public let sourceSchema: SourceSchema
|
||||
public let destinationSchema: DestinationSchema
|
||||
public let sourceSchema: DynamicSchema
|
||||
public let destinationSchema: DynamicSchema
|
||||
|
||||
public func createMappingModel() throws -> (mappingModel: NSMappingModel, migrationType: MigrationType) {
|
||||
|
||||
let sourceModel = self.sourceSchema.rawModel()
|
||||
let destinationModel = self.destinationSchema.rawModel()
|
||||
|
||||
let mappingModel = try NSMappingModel.inferredMappingModel(
|
||||
forSourceModel: sourceModel,
|
||||
destinationModel: destinationModel
|
||||
)
|
||||
return (
|
||||
mappingModel,
|
||||
.lightweight(
|
||||
sourceVersion: self.sourceSchema.modelVersion,
|
||||
destinationVersion: self.destinationSchema.modelVersion
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// MARK: - XcodeMappingModelProvider
|
||||
|
||||
open class XcodeMappingModelProvider<SourceSchema: DynamicSchema, DestinationSchema: DynamicSchema>: LightweightMappingModelProvider<SourceSchema, DestinationSchema> {
|
||||
|
||||
private let mappingModelBundles: [Bundle]
|
||||
|
||||
public required init(source: SourceSchema, destination: DestinationSchema, mappingModelBundles: [Bundle]) {
|
||||
|
||||
self.mappingModelBundles = mappingModelBundles
|
||||
super.init(source: source, destination: destination)
|
||||
}
|
||||
|
||||
public required init(source: SourceSchema, destination: DestinationSchema) {
|
||||
|
||||
self.mappingModelBundles = Bundle.allBundles
|
||||
super.init(source: source, destination: destination)
|
||||
}
|
||||
|
||||
|
||||
// MARK: SchemaMappingProvider
|
||||
|
||||
public override func createMappingModel() throws -> (mappingModel: NSMappingModel, migrationType: MigrationType) {
|
||||
|
||||
let sourceModel = self.sourceSchema.rawModel()
|
||||
let destinationModel = self.destinationSchema.rawModel()
|
||||
|
||||
if let mappingModel = NSMappingModel(
|
||||
from: self.mappingModelBundles,
|
||||
forSourceModel: sourceModel,
|
||||
@@ -86,18 +124,7 @@ open class XcodeMappingModelProvider<S: DynamicSchema, D: DynamicSchema>: Schema
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
let mappingModel = try NSMappingModel.inferredMappingModel(
|
||||
forSourceModel: sourceModel,
|
||||
destinationModel: destinationModel
|
||||
)
|
||||
return (
|
||||
mappingModel,
|
||||
.lightweight(
|
||||
sourceVersion: self.sourceSchema.modelVersion,
|
||||
destinationVersion: self.destinationSchema.modelVersion
|
||||
)
|
||||
)
|
||||
return try super.createMappingModel()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user