Skip to content

Commit

Permalink
Updated Identifiable instance accessors to be disfavored in cases whe…
Browse files Browse the repository at this point in the history
…re their IDs were similarly shaped
  • Loading branch information
dimitribouniol committed Mar 31, 2024
1 parent 720b897 commit 11c79dd
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion Sources/CodableDatastore/Datastore/Datastore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1010,25 +1010,29 @@ extension Datastore where AccessMode == ReadWrite {
public var readOnly: Datastore<Version, CodedType, IdentifierType, ReadOnly> { self as Any as! Datastore<Version, CodedType, IdentifierType, ReadOnly> }
}

// MARK: Idetifiable CodedType
// MARK: Identifiable CodedType

extension Datastore where CodedType: Identifiable, IdentifierType == CodedType.ID {
/// Persist an instance to the data store.
///
/// If an instance does not already exist for the specified identifier, it will be created. If an instance already exists, it will be updated.
/// - Parameter instance: The instance to persist.
@_disfavoredOverload
public func persist(_ instance: CodedType) async throws where AccessMode == ReadWrite {
try await self.persist(instance, to: instance.id)
}

@_disfavoredOverload
public func delete(_ instance: CodedType) async throws where AccessMode == ReadWrite {
try await self.delete(instance.id)
}

@_disfavoredOverload
public func load(_ instance: CodedType) async throws -> CodedType? {
try await self.load(instance.id)
}

@_disfavoredOverload
public func observe(_ instance: CodedType) async throws -> some TypedAsyncSequence<ObservedEvent<IdentifierType, CodedType>> {
try await observe(instance.id)
}
Expand Down

0 comments on commit 11c79dd

Please sign in to comment.