-
|
The documentation and examples use the It seems that when doing something like this, we lose the ability e.g. to observe the changes of the return type. class Wrapper {
func fetchReminder(id: String) -> Reminder {
@FetchAll(
Reminder.where({ $0.id == id })
)
var reminder
return reminder
}
} |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
|
The If you're not needing to subscribe to changes, we recommend executing queries directly: @Dependency(\.defaultDatabase) var database
let reminder = try database.read { db in
try Reminder.find(id).fetchOne(db)
}
reminder // Reminder?Let us know if there's a part of the docs you were looking at that we could improve! |
Beta Was this translation helpful? Give feedback.
Hi @pahnev, there are a number of approaches to this, but we personally feel like these kinds of wrapper objects to hide the database from your codebase aren't worth the effort.
If you really want the wrapper to work for you, you will need it to return
FetchOne/FetchAll/Fetchtypes, not just the data, so that you can retain observability. Here is an example of a SwiftUI view that gets its@FetchOne var reminderfrom a wrapper object like you outlined above: