Closed apptekstudios closed 4 years ago
Hello @apptekstudios,
Thanks for your interest and suggestions! I will not accept this pull request, though, and I suggest you keep on using DatabaseRequest and DatabaseEditable in your own apps, or in their dedicated repository.
Four reasons why:
All in all, I'm very thankful, and I'm very willing to learn from users who use GRDBCombine in their applications. I'll also keep on directing the library so that it remains on a path that fosters a sane usage of the database, especially regarding concurrency and consistency traps.
On the same vein as DatabaseRequest, I'm looking at @FetchRequest. Unfortunately, it can't be implemented today with the current version of Swift (at least, it wasn't last time I tried). One of the reasons why it is interesting is that it grabs the database connection from the environment. The other reason why it is interesting is, obviously, that it is the Apple-vetted technique in order to feed SwiftUI from Core Data. We should get inspiration from it for GRDBCombine.
Thank you for your detailed response @groue! These are good reasons and I appreciate the time and thought you put into the design/documentation of GRDB 😃I agree that database injection is currently an issue in SwiftUI and hope that we will have the ability to create property wrappers that access the environment (such as FetchRequest) in future versions 🤞
FYI for anyone who reads this in search of a SwiftUI-oriented GRDB package: https://github.com/apptekstudios/AS_GRDBSwiftUI As I refine my generalisable code I will be updating this repository 😄
Thanks for the link, @apptekstudios :-) Happy GRDB!
FYI @groue I've finally figured out how to achieve the equivalent of @FetchRequest. This is now implemented in my repo with a fully-functional demo project 😄
Here's the link again here in case anyone searches for it: https://github.com/apptekstudios/AS_GRDBSwiftUI I will be maintaining this package as it is now in heavy use in one of our apps. 👍 🎉 It makes sense to keep this separate to GRDBCombine due to the dependence on SwiftUI.
Hello @apptekstudios! That's super cool, thank you. I'll have a look, and I'm quite looking for learning new techniques :-)
I've been loving getting to know GRDB over the last few days and thought I would experiment with how to best integrate it into SwiftUI projects. This PR adds two types that both conform to
ObservableObject
and can be used directly in SwiftUI views.DatabaseRequest
allows one to define a fetchRequest and have the view automatically update when the result changes.DatabaseEditable
allows for SwiftUI views to store and mutate a value conforming toMutablePersistableRecord
. It provides options for automatically updating the database row on mutation, as well as manually committing changes to the database by callingcommitChanges()
.These are best explained by checking out the SwiftUI demo project I have included in the PR 😄