File tree Expand file tree Collapse file tree 1 file changed +18
-1
lines changed
Sources/CodableDatastore/Datastore Expand file tree Collapse file tree 1 file changed +18
-1
lines changed Original file line number Diff line number Diff line change @@ -885,14 +885,31 @@ extension Datastore where AccessMode == ReadWrite {
885885
886886 @discardableResult
887887 public func delete( _ idenfifier: IdentifierType ) async throws -> CodedType {
888+ guard let deletedInstance = try await deleteIfPresent ( idenfifier)
889+ else { throw DatastoreInterfaceError . instanceNotFound }
890+ return deletedInstance
891+ }
892+
893+ @discardableResult
894+ public func deleteIfPresent( _ idenfifier: IdentifierType ) async throws -> CodedType ? {
888895 try await warmupIfNeeded ( )
889896
890897 return try await persistence. _withTransaction (
891898 actionName: " Delete Entry " ,
892899 options: [ . idempotent]
893900 ) { transaction, _ in
894901 /// Get a cursor to the entry within the primary index.
895- let existingEntry = try await transaction. primaryIndexCursor ( for: idenfifier, datastoreKey: self . key)
902+ let existingEntry : ( cursor: any InstanceCursorProtocol , instanceData: Data , versionData: Data )
903+ do {
904+ existingEntry = try await transaction. primaryIndexCursor ( for: idenfifier, datastoreKey: self . key)
905+ } catch DatastoreInterfaceError . instanceNotFound {
906+ return nil
907+ } catch DatastoreInterfaceError . datastoreKeyNotFound {
908+ /// There isn't a datastore yet, so no entries would exist either.
909+ return nil
910+ } catch {
911+ throw error
912+ }
896913
897914 /// Delete the instance at that cursor.
898915 try await transaction. deletePrimaryIndexEntry ( cursor: existingEntry. cursor, datastoreKey: self . key)
You can’t perform that action at this time.
0 commit comments