Comments (6)
Hello @sobri909,
Thanks for sponsoring the project! 💝
The mention of an _id table is mysterious
Agreed.
I suspect @Observable
.
I find a mention of _id
in https://callistaenterprise.se/blogg/teknik/2023/08/14/new-swift-observation/.
This article mentions underscore-prefixed keys as well: https://www.hackingwithswift.com/books/ios-swiftui/adding-codable-conformance-to-an-observable-class.
Maybe the best technique is to remove Codable
conformance, and provide an explicit implementation of encode(to:)
on the side of init(row:)
.
That's a lot of boilerplate 😬
Maybe detaching the data layer from SwiftUI could help (i.e. have some UI observable objects feed from immutable record structs). Codable structs don't need explicit encode(to:)
and init(row:)
. And given the bad interaction of @Observable
and Codable
, insisting on fighting the immaturity limits of Apple code might be the wrong way.
from grdb.swift.
Yep, problem conclusively solved 👍🏼 Thanks again!
from grdb.swift.
Oh, the ForeignKey(["timelineItemId"], to: ["id"])
on the toMany()
was a failed attempt to work around the problem (if I'm even identifying the problem correctly). It achieved nothing, with identical results to the plain public static let samples = hasMany(LocomotionSample.self).forKey("samples")
declaration.
from grdb.swift.
Oh I missed out the row decoding:
@Observable
public class LocomotionSample: Record, Identifiable, Codable {
...
required init(row: Row) throws {
id = row["id"]
date = row["date"]
secondsFromGMT = row["secondsFromGMT"]
source = row["source"]
movingState = MovingState(rawValue: row["movingState"])!
recordingState = RecordingState(rawValue: row["recordingState"])!
timelineItemId = row["timelineItemId"]
latitude = row["latitude"]
longitude = row["longitude"]
altitude = row["altitude"]
horizontalAccuracy = row["horizontalAccuracy"]
verticalAccuracy = row["verticalAccuracy"]
speed = row["speed"]
course = row["course"]
classifiedActivityType = row["classifiedActivityType"]
confirmedActivityType = row["confirmedActivityType"]
try super.init(row: row)
}
...
}
@Observable
public class TimelineItemBase: Record, Identifiable, Codable {
...
required init(row: Row) throws {
id = row["id"]
source = row["source"]
isVisit = row["isVisit"]
startDate = row["startDate"]
endDate = row["endDate"]
deleted = row["deleted"]
previousItemId = row["previousItemId"]
nextItemId = row["nextItemId"]
stepCount = row["stepCount"]
floorsAscended = row["floorsAscended"]
floorsDescended = row["floorsDescended"]
averageAltitude = row["averageAltitude"]
activeEnergyBurned = row["activeEnergyBurned"]
averageHeartRate = row["averageHeartRate"]
maxHeartRate = row["maxHeartRate"]
try super.init(row: row)
}
...
}
I'm currently fiddling about in the debugger, trying to breakpoint in row decoding to see if I can find my whoopsie there. No luck so far. Feels like it's got to be some dumb typo, or silly misunderstanding of API, but I just can't see it yet 😑
from grdb.swift.
Ooh, you got it! Thanks!
Commenting out @Obserable
fixes it! 🎉
In retrospect, I should've been clued by the underscore. But I was too busy being convinced it was something to do with me using GRDB wrong. Heh.
For structs vs classes, yeah I initially went that way with the rewrite. But as I ported over more of the complexity from the old codebase it became clear structs weren't going to be up to challenge. I still have to cut corners for efficiency reasons in some places, so copying/refetching structs is still going to be too costly. Can't win 'em all.
Hopefully I'll be able to get away with only using Record classes for the core high-pressure models, and can rely on struct models for the rest. Fingers crossed.
Anyway, thanks again! It would've taken me forever to get to realising it might be to do with @Observable
.
from grdb.swift.
Great, @sobri909 👍 I agree that structs are not a panacea, especially large ones!
Shall we close this issue? You can always open a new one if you have another question.
from grdb.swift.
Related Issues (20)
- Request: Add citation to the repo HOT 3
- Cocoapods hasn't published since 6.24.1 HOT 2
- Cocoapods 6.26.0 release is not available in Cocapods Specs repo HOT 1
- Privacy Manifest: Entry missing for accessing file timestamps via creationDate API HOT 4
- When transaction updating multiple records in the database, if one of the records does not exist, it leads to update failure. HOT 4
- Avoid conflict with other SPM packages by renaming the CSQLite SPM target
- ValueObservation.tracking called on the updating thread HOT 5
- GRDB does not seem to copy over all rows when inserting within a migration HOT 4
- Unable to decode database NULL value as Swift nil value of type Int? when using ScopeAdapter built from splittingRowAdapters HOT 13
- PlayerRequest.swift is identical in GRDBAsyncDemo and GRDBCombineDemo HOT 4
- App crashes with many (not all) users running iOS 17.4.1 HOT 8
- Library fails to compile when targeting Linux using a SQLite library that doesn't support snapshots HOT 3
- 0xdead10cc prevention — `checkForSuspensionViolation` on every `Statement.step` HOT 6
- Weird db read issue HOT 7
- Error for query count grouped HOT 4
- GRDB 6 missing DatabasePool/DatabaseQueue interchangeability HOT 3
- Thread running at User-initiated quality-of-service class waiting on a thread without a QoS class specified (base priority 0). Investigate ways to avoid priority inversions HOT 1
- [best practices] How can insert a same type of record into 2 tables HOT 8
- Using experimental CTE
- How to store database connection HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from grdb.swift.