Skip to content

Commit 4069be9

Browse files
authored
StructuredQueries 0.22.0 support (#238)
* wip * wip * wip * wip * wip * wip * wip * wip * wip * wip
1 parent 547a508 commit 4069be9

25 files changed

+495
-354
lines changed

Examples/CaseStudies/Animations.swift

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import SwiftUI
44
struct AnimationsCaseStudy: SwiftUICaseStudy {
55
let readMe = """
66
This demonstrates how to animate fetching data from the database, or when data changes in \
7-
the database. Simply provide the `animation` argument to `fetchAll` (or the other querying \
8-
tools, such as `fetch` and `fetchOne`).
7+
the database. Simply provide the `animation` argument to `@FetchAll` (or the other querying \
8+
tools, such as `@Fetch` and `@FetchOne`).
99
1010
This is analogous to how animations work in SwiftData in which one provides an `animation` \
1111
argument to the `@Query` macro.
@@ -35,8 +35,10 @@ struct AnimationsCaseStudy: SwiftUICaseStudy {
3535
as: UTF8.self
3636
)
3737
try await database.write { db in
38-
try Fact.insert(Fact.Draft(body: fact))
39-
.execute(db)
38+
try Fact.insert {
39+
Fact.Draft(body: fact)
40+
}
41+
.execute(db)
4042
}
4143
}
4244
} catch {}

Examples/CaseStudies/DynamicQuery.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,10 @@ struct DynamicQueryDemo: SwiftUICaseStudy {
6868
as: UTF8.self
6969
)
7070
try await database.write { db in
71-
try Fact.insert(Fact.Draft(body: fact))
72-
.execute(db)
71+
try Fact.insert {
72+
Fact.Draft(body: fact)
73+
}
74+
.execute(db)
7375
}
7476
}
7577
} catch {}

Examples/CaseStudies/ObservableModelDemo.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,10 @@ private class Model {
6565
as: UTF8.self
6666
)
6767
try await database.write { db in
68-
try Fact.insert(Fact.Draft(body: fact))
69-
.execute(db)
68+
try Fact.insert {
69+
Fact.Draft(body: fact)
70+
}
71+
.execute(db)
7072
}
7173
}
7274
}

Examples/CaseStudies/SwiftUIDemo.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,10 @@ struct SwiftUIDemo: SwiftUICaseStudy {
4444
as: UTF8.self
4545
)
4646
try await database.write { db in
47-
try Fact.insert(Fact.Draft(body: fact))
48-
.execute(db)
47+
try Fact.insert {
48+
Fact.Draft(body: fact)
49+
}
50+
.execute(db)
4951
}
5052
}
5153
} catch {}

Examples/CaseStudies/TransactionDemo.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,10 @@ struct TransactionDemo: SwiftUICaseStudy {
4646
as: UTF8.self
4747
)
4848
try await database.write { db in
49-
try Fact.insert(Fact.Draft(body: fact))
50-
.execute(db)
49+
try Fact.insert {
50+
Fact.Draft(body: fact)
51+
}
52+
.execute(db)
5153
}
5254
}
5355
} catch {}

Examples/CaseStudies/UIKitDemo.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import UIKitNavigation
77
final class UIKitCaseStudyViewController: UICollectionViewController, UIKitCaseStudy {
88
let caseStudyTitle = "UIKit"
99
let readMe = """
10-
This case study demonstrates how to use the 'fetchAll' tool in a UIKit app. The view \
10+
This case study demonstrates how to use the `@FetchAll` tool in a UIKit app. The view \
1111
controller observes changes to the database and updates a collection view when data is added \
1212
or removed.
1313
"""
@@ -96,8 +96,10 @@ final class UIKitCaseStudyViewController: UICollectionViewController, UIKitCaseS
9696
if let fact {
9797
await withErrorReporting {
9898
try await database.write { db in
99-
try Fact.insert(Fact.Draft(body: fact))
100-
.execute(db)
99+
try Fact.insert {
100+
Fact.Draft(body: fact)
101+
}
102+
.execute(db)
101103
}
102104
}
103105
}

Examples/Examples.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved

Lines changed: 3 additions & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Examples/Reminders/Schema.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ struct Reminder: Hashable, Identifiable {
5656
extension Updates<Reminder> {
5757
mutating func toggleStatus() {
5858
self.status = Case(self.status)
59-
.when(Reminder.Status.incomplete, then: Reminder.Status.completing)
60-
.else(Reminder.Status.incomplete)
59+
.when(#bind(.incomplete), then: #bind(.completing))
60+
.else(#bind(.incomplete))
6161
}
6262
}
6363

@@ -101,13 +101,13 @@ extension Tag {
101101
}
102102

103103
@Table("remindersTags")
104-
struct ReminderTag: Hashable, Identifiable {
104+
struct ReminderTag: Identifiable {
105105
let id: UUID
106-
var reminderID: Reminder.ID
107-
var tagID: Tag.ID
106+
let reminderID: Reminder.ID
107+
let tagID: Tag.ID
108108
}
109109

110-
@Table @Selection
110+
@Table
111111
struct ReminderText: FTS5 {
112112
let rowid: Int
113113
let title: String
@@ -335,7 +335,7 @@ func appDatabase() throws -> any DatabaseWriter {
335335
} forEachRow: { _, _ in
336336
Values($handleReminderStatusUpdate())
337337
} when: { _, new in
338-
new.status.eq(Reminder.Status.completing)
338+
new.status.eq(#bind(.completing))
339339
}
340340
)
341341
.execute(db)
@@ -359,7 +359,7 @@ func handleReminderStatusUpdate() {
359359
try await clock.sleep(for: .seconds(5))
360360
try await database.write { db in
361361
try Reminder
362-
.where { $0.status.eq(Reminder.Status.completing) }
362+
.where { $0.status.eq(#bind(.completing)) }
363363
.update { $0.status = .completed }
364364
.execute(db)
365365
}

Examples/SyncUps/RecordMeeting.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,9 @@ final class RecordMeetingModel: HashableObject {
124124
try? await clock.sleep(for: .seconds(0.4))
125125
await withErrorReporting {
126126
try await database.write { [now, syncUp, transcript] db in
127-
try Meeting.insert(
127+
try Meeting.insert {
128128
Meeting.Draft(date: now, syncUpID: syncUp.id, transcript: transcript)
129-
)
129+
}
130130
.execute(db)
131131
}
132132
}

Examples/SyncUps/SyncUpsList.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,11 @@ final class SyncUpsListModel {
4242
#endif
4343

4444
@Selection
45-
struct Row {
45+
struct Row: Identifiable {
4646
let attendeeCount: Int
4747
let syncUp: SyncUp
48+
49+
var id: SyncUp.ID { syncUp.id }
4850
}
4951
}
5052

@@ -54,7 +56,7 @@ struct SyncUpsList: View {
5456

5557
var body: some View {
5658
List {
57-
ForEach(model.syncUps, id: \.syncUp.id) { state in
59+
ForEach(model.syncUps) { state in
5860
NavigationLink(value: AppModel.Path.detail(SyncUpDetailModel(syncUp: state.syncUp))) {
5961
CardView(syncUp: state.syncUp, attendeeCount: state.attendeeCount)
6062
}

0 commit comments

Comments
 (0)