Skip to content

Commit ba92711

Browse files
committed
clean up
1 parent eae64d1 commit ba92711

File tree

7 files changed

+54
-33
lines changed

7 files changed

+54
-33
lines changed

Examples/CloudKitDemo/CountersListFeature.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ struct CounterRow: View {
129129
#Preview {
130130
let _ = try! prepareDependencies {
131131
try $0.bootstrapDatabase()
132+
try $0.defaultDatabase.seedSampleData()
132133
}
133134
NavigationStack {
134135
CountersListView()

Examples/CloudKitDemo/Schema.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,16 @@ extension DependencyValues {
4747
}
4848

4949
private let logger = Logger(subsystem: "CloudKitDemo", category: "Database")
50+
51+
#if DEBUG
52+
extension DatabaseWriter {
53+
func seedSampleData() throws {
54+
try write { db in
55+
try db.seed {
56+
Counter.Draft(count: 24)
57+
Counter.Draft(count: 1729)
58+
}
59+
}
60+
}
61+
}
62+
#endif

Examples/SyncUps/App.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ struct AppView: View {
7777
}
7878

7979
#Preview("Happy path") {
80-
let _ = try! prepareDependencies { try $0.bootstrapDatabase() }
80+
let _ = try! prepareDependencies {
81+
try $0.bootstrapDatabase()
82+
try $0.defaultDatabase.seedSampleData()
83+
}
8184
AppView(model: AppModel())
8285
}

Examples/SyncUps/Schema.swift

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -152,35 +152,37 @@ extension DependencyValues {
152152
private let logger = Logger(subsystem: "SyncUps", category: "Database")
153153

154154
#if DEBUG
155-
extension Database {
155+
extension DatabaseWriter {
156156
func seedSampleData() throws {
157-
try seed {
158-
SyncUp(id: UUID(1), seconds: 60, theme: .appOrange, title: "Design")
159-
SyncUp(id: UUID(2), seconds: 60 * 10, theme: .periwinkle, title: "Engineering")
160-
SyncUp(id: UUID(3), seconds: 60 * 30, theme: .poppy, title: "Product")
157+
try write { db in
158+
try db.seed {
159+
SyncUp(id: UUID(1), seconds: 60, theme: .appOrange, title: "Design")
160+
SyncUp(id: UUID(2), seconds: 60 * 10, theme: .periwinkle, title: "Engineering")
161+
SyncUp(id: UUID(3), seconds: 60 * 30, theme: .poppy, title: "Product")
161162

162-
for name in ["Blob", "Blob Jr", "Blob Sr", "Blob Esq", "Blob III", "Blob I"] {
163-
Attendee.Draft(name: name, syncUpID: UUID(1))
164-
}
165-
for name in ["Blob", "Blob Jr"] {
166-
Attendee.Draft(name: name, syncUpID: UUID(2))
167-
}
168-
for name in ["Blob Sr", "Blob Jr"] {
169-
Attendee.Draft(name: name, syncUpID: UUID(3))
170-
}
163+
for name in ["Blob", "Blob Jr", "Blob Sr", "Blob Esq", "Blob III", "Blob I"] {
164+
Attendee.Draft(name: name, syncUpID: UUID(1))
165+
}
166+
for name in ["Blob", "Blob Jr"] {
167+
Attendee.Draft(name: name, syncUpID: UUID(2))
168+
}
169+
for name in ["Blob Sr", "Blob Jr"] {
170+
Attendee.Draft(name: name, syncUpID: UUID(3))
171+
}
171172

172-
Meeting.Draft(
173-
date: Date().addingTimeInterval(-60 * 60 * 24 * 7),
174-
syncUpID: UUID(1),
175-
transcript: """
176-
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor \
177-
incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud \
178-
exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute \
179-
irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla \
180-
pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia \
181-
deserunt mollit anim id est laborum.
182-
"""
183-
)
173+
Meeting.Draft(
174+
date: Date().addingTimeInterval(-60 * 60 * 24 * 7),
175+
syncUpID: UUID(1),
176+
transcript: """
177+
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor \
178+
incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud \
179+
exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute \
180+
irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla \
181+
pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia \
182+
deserunt mollit anim id est laborum.
183+
"""
184+
)
185+
}
184186
}
185187
}
186188
}

Examples/SyncUps/SyncUpDetail.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,8 +273,9 @@ struct MeetingView: View {
273273
#Preview {
274274
let syncUp = try! prepareDependencies {
275275
try $0.bootstrapDatabase()
276+
try $0.defaultDatabase.seedSampleData()
276277
return try $0.defaultDatabase.read { db in
277-
try SyncUp.limit(1).fetchOne(db)!
278+
try SyncUp.fetchOne(db)!
278279
}
279280
}
280281
NavigationStack {

Examples/SyncUps/SyncUpsList.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,7 @@ final class SyncUpsListModel {
3434
#if DEBUG
3535
func seedDatabase() {
3636
withErrorReporting {
37-
try database.write { db in
38-
try db.seedSampleData()
39-
}
37+
try database.seedSampleData()
4038
}
4139
}
4240
#endif
@@ -156,6 +154,7 @@ private struct SeedDatabaseTip: Tip {
156154
#Preview {
157155
let _ = try! prepareDependencies {
158156
try $0.bootstrapDatabase()
157+
try $0.defaultDatabase.seedSampleData()
159158
}
160159
NavigationStack {
161160
SyncUpsList(model: SyncUpsListModel())

Sources/SQLiteData/CloudKit/SyncEngine.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1789,8 +1789,9 @@
17891789
switch error.code {
17901790
case .referenceViolation:
17911791
enqueuedUnsyncedRecordID = true
1792-
try UnsyncedRecordID.insert(or: .ignore) {
1792+
try UnsyncedRecordID.insert {
17931793
UnsyncedRecordID(recordID: failedRecordID)
1794+
} onConflictDoUpdate: { _ in
17941795
}
17951796
.execute(db)
17961797
syncEngine.state.remove(pendingRecordZoneChanges: [.deleteRecord(failedRecordID)])
@@ -1955,8 +1956,9 @@
19551956
else {
19561957
throw error
19571958
}
1958-
try UnsyncedRecordID.insert(or: .ignore) {
1959+
try UnsyncedRecordID.insert {
19591960
UnsyncedRecordID(recordID: serverRecord.recordID)
1961+
} onConflictDoUpdate: { _ in
19601962
}
19611963
.execute(db)
19621964
}

0 commit comments

Comments
 (0)