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