Skip to content

Commit

Permalink
removing Obsolete code
Browse files Browse the repository at this point in the history
  • Loading branch information
leogdion committed Sep 9, 2024
1 parent 334a392 commit 0005b5a
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 142 deletions.
14 changes: 0 additions & 14 deletions Sources/DataThespian/Database.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,7 @@

public import SwiftData

public struct ModelID<T: PersistentModel>: Sendable, Identifiable {

public var id : PersistentIdentifier.ID {
return persistentIdentifier.id
}
public let persistentIdentifier: PersistentIdentifier

enum Error: Swift.Error { case notFound(PersistentIdentifier) }
}

extension ModelID where T: PersistentModel {
public init(_ model: T) { self.init(persistentIdentifier: model.persistentModelID) }

fileprivate static func ifMap(_ model: T?) -> ModelID? { model.map(self.init) }
}

public protocol Database: Sendable {
@discardableResult func delete<T: PersistentModel>(
Expand Down
25 changes: 1 addition & 24 deletions Sources/DataThespian/DatabaseKey.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
}

func insert(_: @escaping @Sendable () -> some PersistentModel) async -> PersistentIdentifier {
// assertionFailure("No Database Set.")
assertionFailure("No Database Set.")
fatalError("No Database Set.")
}

Expand Down Expand Up @@ -84,29 +84,6 @@
}
}

extension DefaultDatabase {
func obsoleteFetch<T>(_: @escaping () -> FetchDescriptor<T>) async throws -> [T]
where T: Sendable, T: PersistentModel {
assertionFailure("No Database Set.")
throw NotImplmentedError.instance
}

func obsoleteDelete(_: some PersistentModel) async { assertionFailure("No Database Set.") }

func obsoleteInsert(_: some PersistentModel) async { assertionFailure("No Database Set.") }

func obsoleteSave() async throws {
assertionFailure("No Database Set.")
throw NotImplmentedError.instance
}

func obsoleteExistingModel<T>(for _: PersistentIdentifier) throws -> T?
where T: Sendable, T: PersistentModel {
assertionFailure("No Database Set.")
throw NotImplmentedError.instance
}
}

fileprivate struct DatabaseKey: EnvironmentKey {
static var defaultValue: any Database { DefaultDatabase.instance }
}
Expand Down
52 changes: 1 addition & 51 deletions Sources/DataThespian/ModelActorDatabase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -91,56 +91,6 @@
}
}

extension ModelActorDatabase {
public func obsoleteDelete(_ model: some PersistentModel & Sendable) async {
assert(isMainThread: false)
assert(model.modelContext == modelContext || model.modelContext == nil)
guard model.modelContext == modelContext else { return }

Self.logger.debug("Delete begun: \(type(of: model).self)")
modelContext.delete(model)
}

public func obsoleteInsert(_ model: some PersistentModel & Sendable) async {
assert(isMainThread: false)
assert(model.modelContext == modelContext || model.modelContext == nil)
guard model.modelContext == modelContext || model.modelContext == nil else { return }
Self.logger.debug("Insert begun: \(type(of: model).self)")
modelContext.insert(model)
}

public func obsoleteDelete<T: PersistentModel & Sendable>(where predicate: Predicate<T>?)
async throws
{
assert(isMainThread: false)

Self.logger.debug("Delete begun: \(T.self)")
try modelContext.delete(model: T.self, where: predicate)
}

public func obsoleteSave() async throws {
assert(isMainThread: false)
Self.logger.debug("Save begun")
try modelContext.save()
}

public func obsoleteFetch<T>(_ selectDescriptor: @escaping @Sendable () -> FetchDescriptor<T>)
async throws -> [T] where T: Sendable, T: PersistentModel
{
assert(isMainThread: false)
Self.logger.debug("Fetch begun: \(T.self)")
return try modelContext.fetch(selectDescriptor())
}

public func fetch<T>(_ selectDescriptor: FetchDescriptor<T>) async throws -> [T]
where T: PersistentModel & Sendable {
assert(isMainThread: false)
Self.logger.debug("Fetch begun: \(T.self)")
return try modelContext.fetch(selectDescriptor)
}

public func obsoleteExistingModel<T>(for objectID: PersistentIdentifier) async throws -> T?
where T: Sendable, T: PersistentModel { try modelContext.existingModel(for: objectID) }
}


#endif
28 changes: 28 additions & 0 deletions Sources/DataThespian/ModelID.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//
// ModelID.swift
// DataThespian
//
// Created by Leo Dion on 9/9/24.
//

#if canImport(SwiftData)

import Foundation

public import SwiftData
public struct ModelID<T: PersistentModel>: Sendable, Identifiable {

public var id : PersistentIdentifier.ID {
return persistentIdentifier.id
}
public let persistentIdentifier: PersistentIdentifier

enum Error: Swift.Error { case notFound(PersistentIdentifier) }
}

extension ModelID where T: PersistentModel {
public init(_ model: T) { self.init(persistentIdentifier: model.persistentModelID) }

internal static func ifMap(_ model: T?) -> ModelID? { model.map(self.init) }
}
#endif
53 changes: 0 additions & 53 deletions Sources/DataThespian/ObsoleteDatabase.swift

This file was deleted.

0 comments on commit 0005b5a

Please sign in to comment.