@@ -45,11 +45,11 @@ view's body is computed, but could also be more.
4545
4646This kind of data processing is exactly what SQLite excels at, and so we can offload this work by
4747modifying the query itself. One can do this with SharingGRDB by using the ` load ` method on
48- ` SharedReader ` in order to load a new key, and hence execute a new query:
48+ `` FetchAll `` , `` FetchOne `` or `` Fetch ` ` in order to load a new key, and hence execute a new query:
4949
5050``` swift
5151struct ContentView : View {
52- @State . SharedReader ( value : []) var items: [Item]
52+ @FetchAll var items: [Item]
5353 @State var filterDate: Date?
5454 @State var order: SortOrder = .reverse
5555
@@ -65,18 +65,16 @@ struct ContentView: View {
6565 private func updateQuery () async {
6666 do {
6767 try await $items.load (
68- .fetchAll (
69- Items
70- .where { $0 .timestamp > #bind (filterDate ?? .distantPast ) }
71- .order {
72- if order == .forward {
73- $0 .timestamp
74- } else {
75- $0 .timestamp .desc ()
76- }
68+ Items
69+ .where { $0 .timestamp > #bind (filterDate ?? .distantPast ) }
70+ .order {
71+ if order == .forward {
72+ $0 .timestamp
73+ } else {
74+ $0 .timestamp .desc ()
7775 }
78- . limit ( 10 )
79- )
76+ }
77+ . limit ( 10 )
8078 )
8179 } catch {
8280 // Handle error...
@@ -91,6 +89,3 @@ struct ContentView: View {
9189> initial ` @FetchAll ` 's value, taken from the parent. To manage the state of this dynamic query
9290> locally to this view, we use ` @State @FetchAll ` , instead, and to access the underlying
9391> ` FetchAll ` value you can use ` wrappedValue ` .
94-
95- > Note: We are using the `` Sharing/SharedReaderKey/fetchAll(_:database:) `` style of
96- > querying the database. See < doc:Fetching > for more APIs that can be used.
0 commit comments