Skip to content

Commit 67ce6bf

Browse files
committed
Workaround for generated column observation behavior.
1 parent a01f0d3 commit 67ce6bf

File tree

8 files changed

+14
-68
lines changed

8 files changed

+14
-68
lines changed

Sources/SQLiteData/CloudKit/SyncMetadata.swift

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,16 +100,17 @@
100100
@Column(generated: .virtual)
101101
public let hasLastKnownServerRecord: Bool
102102

103+
/// The time the user last modified the record.
104+
public let userModificationTime: Int64
105+
103106
/// Determines if the record associated with this metadata is currently shared in CloudKit.
104107
///
105108
/// This can only return `true` for root records. For example, the metadata associated with a
106109
/// `RemindersList` can have `isShared == true`, but a `Reminder` associated with the list
107110
/// will have `isShared == false`.
108-
@Column(generated: .virtual)
109-
public let isShared: Bool
110-
111-
/// The time the user last modified the record.
112-
public let userModificationTime: Int64
111+
public var isShared: Bool {
112+
share != nil
113+
}
113114
}
114115

115116
@available(iOS 17, macOS 14, tvOS 17, watchOS 10, *)
@@ -129,6 +130,13 @@
129130
public var parentRecordType: TableColumn<SyncMetadata, String?> {
130131
parentRecordID.parentRecordType
131132
}
133+
134+
// NB: Workaround for https://github.com/groue/GRDB.swift/discussions/1844
135+
public var isShared: some QueryExpression<Bool> {
136+
#sql("""
137+
(\(QueryValue.self)."isShared" AND (\(self.share) OR 1))
138+
""")
139+
}
132140
}
133141

134142
@available(iOS 17, macOS 14, tvOS 17, watchOS 10, *)
@@ -163,7 +171,6 @@
163171
self._lastKnownServerRecordAllFields = _lastKnownServerRecordAllFields
164172
self.share = share
165173
self.hasLastKnownServerRecord = lastKnownServerRecord != nil
166-
self.isShared = share != nil
167174
self.userModificationTime = userModificationTime
168175
self._isDeleted = false
169176
}

Tests/SQLiteDataTests/CloudKitTests/AccountLifecycleTests.swift

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,6 @@
172172
│ share: nil, │
173173
│ _isDeleted: false, │
174174
│ hasLastKnownServerRecord: true, │
175-
│ isShared: false, │
176175
│ userModificationTime: 0 │
177176
│ ) │
178177
├────────────────────────────────────────────────────────────────────┤
@@ -194,7 +193,6 @@
194193
│ share: nil, │
195194
│ _isDeleted: false, │
196195
│ hasLastKnownServerRecord: false, │
197-
│ isShared: false, │
198196
│ userModificationTime: 0 │
199197
│ ) │
200198
└────────────────────────────────────────────────────────────────────┘
@@ -258,7 +256,6 @@
258256
│ share: nil, │
259257
│ _isDeleted: false, │
260258
│ hasLastKnownServerRecord: true, │
261-
│ isShared: false, │
262259
│ userModificationTime: 0 │
263260
│ ) │
264261
├─────────────────────────────────────────────────────────────────────────────────────────┤
@@ -294,7 +291,6 @@
294291
│ share: nil, │
295292
│ _isDeleted: false, │
296293
│ hasLastKnownServerRecord: true, │
297-
│ isShared: false, │
298294
│ userModificationTime: 0 │
299295
│ ) │
300296
└─────────────────────────────────────────────────────────────────────────────────────────┘
@@ -422,7 +418,6 @@
422418
│ ), │
423419
│ _isDeleted: false, │
424420
│ hasLastKnownServerRecord: true, │
425-
│ isShared: true, │
426421
│ userModificationTime: 0 │
427422
│ ) │
428423
├─────────────────────────────────────────────────────────────────────────────────────────────────────┤
@@ -444,7 +439,6 @@
444439
│ share: nil, │
445440
│ _isDeleted: false, │
446441
│ hasLastKnownServerRecord: false, │
447-
│ isShared: false, │
448442
│ userModificationTime: 0 │
449443
│ ) │
450444
└─────────────────────────────────────────────────────────────────────────────────────────────────────┘
@@ -519,7 +513,6 @@
519513
│ ), │
520514
│ _isDeleted: false, │
521515
│ hasLastKnownServerRecord: true, │
522-
│ isShared: true, │
523516
│ userModificationTime: 0 │
524517
│ ) │
525518
├─────────────────────────────────────────────────────────────────────────────────────────────────────┤
@@ -555,7 +548,6 @@
555548
│ share: nil, │
556549
│ _isDeleted: false, │
557550
│ hasLastKnownServerRecord: true, │
558-
│ isShared: false, │
559551
│ userModificationTime: 0 │
560552
│ ) │
561553
└─────────────────────────────────────────────────────────────────────────────────────────────────────┘

Tests/SQLiteDataTests/CloudKitTests/AttachedMetadatabaseTests.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@
5757
│ │ share: nil, │
5858
│ │ _isDeleted: false, │
5959
│ │ hasLastKnownServerRecord: true, │
60-
│ │ isShared: false, │
6160
│ │ userModificationTime: 0 │
6261
│ │ ) │
6362
└─────────────────────┴────────────────────────────────────────────────────────────────────┘

Tests/SQLiteDataTests/CloudKitTests/FetchRecordZoneChangesTests.swift

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,6 @@
547547
│ share: nil, │
548548
│ _isDeleted: false, │
549549
│ hasLastKnownServerRecord: true, │
550-
│ isShared: false, │
551550
│ userModificationTime: 0 │
552551
│ ) │
553552
└────────────────────────────────────────────────────────────┘
@@ -630,7 +629,6 @@
630629
│ share: nil, │
631630
│ _isDeleted: false, │
632631
│ hasLastKnownServerRecord: true, │
633-
│ isShared: false, │
634632
│ userModificationTime: 0 │
635633
│ ) │
636634
└────────────────────────────────────────────────────────────┘
@@ -700,7 +698,6 @@
700698
│ share: nil, │
701699
│ _isDeleted: false, │
702700
│ hasLastKnownServerRecord: true, │
703-
│ isShared: false, │
704701
│ userModificationTime: 0 │
705702
│ ) │
706703
└────────────────────────────────────────────────────────────────┘

0 commit comments

Comments
 (0)