Skip to content

Commit 2a4ce7c

Browse files
committed
Cleanup
1 parent 34faec3 commit 2a4ce7c

File tree

2 files changed

+18
-16
lines changed

2 files changed

+18
-16
lines changed

TestApp/Sources/Data/Bookmark.swift

+7-6
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,16 @@ final class BookmarkRepository {
5353
}
5454
}
5555

56-
func add(_ bookmark: Bookmark) -> AnyPublisher<Bookmark.Id, Error> {
57-
return db.writePublisher { db in
56+
@discardableResult
57+
func add(_ bookmark: Bookmark) async throws -> Bookmark.Id {
58+
try await db.write { db in
5859
try bookmark.insert(db)
5960
return Bookmark.Id(rawValue: db.lastInsertedRowID)
60-
}.eraseToAnyPublisher()
61+
}
6162
}
62-
63-
func remove(_ id: Bookmark.Id) -> AnyPublisher<Void, Error> {
64-
db.writePublisher { db in try Bookmark.deleteOne(db, key: id) }
63+
64+
func remove(_ id: Bookmark.Id) async throws {
65+
try await db.write { db in try Bookmark.deleteOne(db, key: id) }
6566
}
6667

6768
}

TestApp/Sources/Data/Highlight.swift

+11-10
Original file line numberDiff line numberDiff line change
@@ -91,23 +91,24 @@ final class HighlightRepository {
9191
}
9292
}
9393

94-
func add(_ highlight: Highlight) -> AnyPublisher<Highlight.Id, Error> {
95-
return db.writePublisher { db in
94+
@discardableResult
95+
func add(_ highlight: Highlight) async throws -> Highlight.Id {
96+
try await db.write { db in
9697
try highlight.insert(db)
9798
return highlight.id
98-
}.eraseToAnyPublisher()
99+
}
99100
}
100-
101-
func update(_ id: Highlight.Id, color: HighlightColor) -> AnyPublisher<Void, Error> {
102-
return db.writePublisher { db in
101+
102+
func update(_ id: Highlight.Id, color: HighlightColor) async throws {
103+
try await db.write { db in
103104
let filtered = Highlight.filter(Highlight.Columns.id == id)
104105
let assignment = Highlight.Columns.color.set(to: color)
105106
try filtered.updateAll(db, onConflict: nil, assignment)
106-
}.eraseToAnyPublisher()
107+
}
107108
}
108-
109-
func remove(_ id: Highlight.Id) -> AnyPublisher<Void, Error> {
110-
db.writePublisher { db in try Highlight.deleteOne(db, key: id) }
109+
110+
func remove(_ id: Highlight.Id) async throws {
111+
try await db.write { db in try Highlight.deleteOne(db, key: id) }
111112
}
112113

113114
}

0 commit comments

Comments
 (0)