|
97 | 97 | /// next batch of pending changes is processed. |
98 | 98 | public let _isDeleted: Bool |
99 | 99 |
|
100 | | - @Column(generated: .virtual) |
101 | | - public let hasLastKnownServerRecord: Bool |
| 100 | + @Column("hasLastKnownServerRecord", generated: .virtual) |
| 101 | + public let _hasLastKnownServerRecord: Bool |
| 102 | + |
| 103 | + @Column("isShared", generated: .virtual) |
| 104 | + fileprivate let _isShared: Bool |
| 105 | + |
| 106 | + /// The time the user last modified the record. |
| 107 | + public let userModificationTime: Int64 |
| 108 | + |
| 109 | + public var hasLastKnownServerRecord: Bool { |
| 110 | + lastKnownServerRecord != nil |
| 111 | + } |
102 | 112 |
|
103 | 113 | /// Determines if the record associated with this metadata is currently shared in CloudKit. |
104 | 114 | /// |
105 | 115 | /// This can only return `true` for root records. For example, the metadata associated with a |
106 | 116 | /// `RemindersList` can have `isShared == true`, but a `Reminder` associated with the list |
107 | 117 | /// 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 |
| 118 | + public var isShared: Bool { |
| 119 | + _isShared |
| 120 | + } |
113 | 121 | } |
114 | 122 |
|
115 | 123 | @available(iOS 17, macOS 14, tvOS 17, watchOS 10, *) |
|
129 | 137 | public var parentRecordType: TableColumn<SyncMetadata, String?> { |
130 | 138 | parentRecordID.parentRecordType |
131 | 139 | } |
| 140 | + |
| 141 | + // NB: Workaround for https://github.com/groue/GRDB.swift/discussions/1844 |
| 142 | + public var hasLastKnownServerRecord: some QueryExpression<Bool> { |
| 143 | + #sql( |
| 144 | + """ |
| 145 | + ((\(self._hasLastKnownServerRecord) = 1) AND (\(self.lastKnownServerRecord) OR 1)) |
| 146 | + """ |
| 147 | + ) |
| 148 | + } |
| 149 | + |
| 150 | + // NB: Workaround for https://github.com/groue/GRDB.swift/discussions/1844 |
| 151 | + public var isShared: some QueryExpression<Bool> { |
| 152 | + #sql( |
| 153 | + """ |
| 154 | + ((\(self._isShared) = 1) AND (\(self.share) OR 1)) |
| 155 | + """ |
| 156 | + ) |
| 157 | + } |
132 | 158 | } |
133 | 159 |
|
134 | 160 | @available(iOS 17, macOS 14, tvOS 17, watchOS 10, *) |
|
162 | 188 | self.lastKnownServerRecord = lastKnownServerRecord |
163 | 189 | self._lastKnownServerRecordAllFields = _lastKnownServerRecordAllFields |
164 | 190 | self.share = share |
165 | | - self.hasLastKnownServerRecord = lastKnownServerRecord != nil |
166 | | - self.isShared = share != nil |
| 191 | + self._hasLastKnownServerRecord = lastKnownServerRecord != nil |
| 192 | + self._isShared = share != nil |
167 | 193 | self.userModificationTime = userModificationTime |
168 | 194 | self._isDeleted = false |
169 | 195 | } |
|
0 commit comments