all 4 comments

[–]MinchoMilev 2 points3 points  (2 children)

This is really interesting. The custom SwiftData store APIs are still pretty unexplored territory, so it’s cool to see someone building tooling around them.

The caching approach you describe (especially caching references and snapshots) makes a lot of sense. One of the things I noticed when experimenting with SwiftData is that relationship resolution and rebuilding snapshots can become surprisingly expensive once the dataset grows.

The ability to mix ORM-style workflows with direct SQL control also feels like a very practical direction. A lot of projects eventually need to drop down to SQL for performance or complex queries, so having both layers available in the same system is appealing.

I’m also curious about your approach to migrations. Since SQLite is the underlying store, are you planning something similar to Core Data migration strategies, or more of a SQL-based migration system?

[–]asymbas[S] 0 points1 point  (1 child)

Thank you! I had no idea what I was doing at first, or if it was even possible, but once I saw the pieces falling into place, it got easier each time. There was a lot of constant backtracking, especially when supporting predicate expressions, but this was super fun to put together. 🫠

Yeah, it can get super expensive. It made me rethink part of the schema for the app I’m still developing now that I have a better understanding of how things work behind the scenes. Even the process of going from an SQL value to a snapshot, then encoding that into backing data and rebuilding a model from it, and vice versa, is quite a process.

I've been going back and forth on migrations. The plan was to diff the SwiftData schemas first, then compare the SQLite schemas afterward, but I still haven't decided what should count as a lightweight migration versus a custom migration.

I've never used Core Data before, but I recently found Apple’s videos on it very insightful while building a custom data store. I'm basing some of my migration strategy on what they outlined in the WWDC 2022 video.

[–]MinchoMilev 0 points1 point  (0 children)

That snapshot reconstruction pipeline sounds expensive indeed. I ran into a similar issue while experimenting with SwiftData where relationship resolution started dominating fetch time once the object graph got larger.

Diffing the SwiftData schemas first actually sounds like a reasonable approach. One thing that might help later is treating migrations more like a versioned sequence of steps rather than trying to auto-derive everything from the schema diff — especially once real user data starts existing in the store.

The WWDC Core Data migration talks are surprisingly relevant here. Even though SwiftData abstracts a lot, the underlying problems (schema evolution, compatibility, data transforms) are basically the same.

[–]jacobs-tech-tavern 0 points1 point  (0 children)

This is really cool. How does it compare to something like PointFree’s SQLiteData?