Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include animation identity in fetch key #27

Merged
merged 3 commits into from
Feb 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/groue/GRDB.swift",
"state" : {
"revision" : "c7205b172f38439e7ee62c208d1d76fa353c0a81",
"version" : "7.2.0"
"revision" : "6eba24d16952452a8a54f6a639491f3c8215527f",
"version" : "7.3.0"
}
},
{
Expand Down Expand Up @@ -60,8 +60,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-dependencies",
"state" : {
"revision" : "52b5e1a09dc016e64ce253e19ab3124b7fae9ac9",
"version" : "1.7.0"
"revision" : "121a428c505c01c4ce02d5ada1c8fc3da93afce9",
"version" : "1.8.0"
}
},
{
Expand Down Expand Up @@ -105,8 +105,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-sharing",
"state" : {
"revision" : "10ba53dd428aed9fc4a1543d3271860a6d4b8dd2",
"version" : "2.3.0"
"revision" : "2c840cf2ae0526ad6090e7796c4e13d9a2339f4a",
"version" : "2.3.3"
}
},
{
Expand All @@ -123,8 +123,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/xctest-dynamic-overlay",
"state" : {
"revision" : "b444594f79844b0d6d76d70fbfb3f7f71728f938",
"version" : "1.5.1"
"revision" : "39de59b2d47f7ef3ca88a039dff3084688fe27f4",
"version" : "1.5.2"
}
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ whereas you use the `@Query` macro with SwiftData:
The `@SharedReader` property wrapper takes a variety of options, detailed more in <doc:Fetching>,
and allows you to write raw SQL queries for fetching and aggregating data from your database. It
is also possibly to construct SQL queries using GRDB's query builder syntax. See
[`fetch`](<doc:Sharing/SharedReaderKey/fetch(_:database:scheduler:)-8m3f7>) for more information.
[`fetch`](<doc:Sharing/SharedReaderKey/fetch(_:database:)-3qcpd>) for more information.

### Fetching data for an @Observable model

Expand Down
12 changes: 6 additions & 6 deletions Sources/SharingGRDB/Documentation.docc/Articles/Fetching.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ Learn about the various tools for fetching data from a SQLite database.
## Overview

All data fetching happens by providing
[`fetchAll`](<doc:Sharing/SharedReaderKey/fetchAll(sql:arguments:database:scheduler:)>),
[`fetchOne`](<doc:Sharing/SharedReaderKey/fetchOne(sql:arguments:database:scheduler:)>), or
[`fetch`](<doc:Sharing/SharedReaderKey/fetch(_:database:scheduler:)-8m3f7>), to the `@SharedReader`
[`fetchAll`](<doc:Sharing/SharedReaderKey/fetchAll(sql:arguments:database:)>),
[`fetchOne`](<doc:Sharing/SharedReaderKey/fetchOne(sql:arguments:database:)>), or
[`fetch`](<doc:Sharing/SharedReaderKey/fetch(_:database:)-3qcpd>), to the `@SharedReader`
property wrapper. The primary differences between these choices is whether you want to specify your
query as a raw SQL string, or as a query built with GRDB's query building tools.

Expand All @@ -20,7 +20,7 @@ query as a raw SQL string, or as a query built with GRDB's query building tools.
For simple queries it can often be very convenient to specify how you want to fetch data from SQLite
as a raw SQL query string. For example, if you simply want to fetch all records from a table, you
can do so using the
[`fetchAll`](<doc:Sharing/SharedReaderKey/fetchAll(sql:arguments:database:scheduler:)>) key:
[`fetchAll`](<doc:Sharing/SharedReaderKey/fetchAll(sql:arguments:database:)>) key:

```swift
@SharedReader(.fetchAll(sql: "SELECT * FROM items")) var items: [Item]
Expand All @@ -35,7 +35,7 @@ var items: [Item]

Or, if you want to only compute an aggregate of the data in a table, such as the count of the rows,
you can do so using the
[`fetchOne`](<doc:Sharing/SharedReaderKey/fetchOne(sql:arguments:database:scheduler:)>) key:
[`fetchOne`](<doc:Sharing/SharedReaderKey/fetchOne(sql:arguments:database:)>) key:

```swift
@SharedReader(.fetchOne(sql: "SELECT count(*) FROM items"))
Expand Down Expand Up @@ -142,7 +142,7 @@ struct Items: FetchKeyRequest {
```

With this conformance defined one can use
[`fetch`](<doc:Sharing/SharedReaderKey/fetch(_:database:scheduler:)-8m3f7>) key to execute the
[`fetch`](<doc:Sharing/SharedReaderKey/fetch(_:database:)-3qcpd>) key to execute the
query specified by the `Items` type:

```swift
Expand Down
9 changes: 7 additions & 2 deletions Sources/SharingGRDB/Documentation.docc/Extensions/Fetch.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# ``Sharing/SharedReaderKey/fetch(_:database:scheduler:)-8kkig``
# ``Sharing/SharedReaderKey/fetch(_:database:)-3qcpd``

## Overview

Expand All @@ -10,13 +10,18 @@

### Collections

- ``Sharing/SharedReaderKey/fetch(_:database:scheduler:)-8m3f7``
- ``Sharing/SharedReaderKey/fetch(_:database:)-1ee8v``

### SwiftUI integration

- ``Sharing/SharedReaderKey/fetch(_:database:animation:)-rgj4``
- ``Sharing/SharedReaderKey/fetch(_:database:animation:)-j9jb``

### Custom scheduling

- ``Sharing/SharedReaderKey/fetch(_:database:scheduler:)-9arcp``
- ``Sharing/SharedReaderKey/fetch(_:database:scheduler:)-53u9o``

### Sharing infrastructure

- ``FetchKey``
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# ``Sharing/SharedReaderKey/fetchAll(sql:arguments:database:scheduler:)``
# ``Sharing/SharedReaderKey/fetchAll(sql:arguments:database:)``

## Overview

Expand All @@ -7,3 +7,7 @@
### SwiftUI integration

- ``Sharing/SharedReaderKey/fetchAll(sql:arguments:database:animation:)``

### Custom scheduling

- ``Sharing/SharedReaderKey/fetchAll(sql:arguments:database:scheduler:)``
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# ``Sharing/SharedReaderKey/fetchOne(sql:arguments:database:scheduler:)``
# ``Sharing/SharedReaderKey/fetchOne(sql:arguments:database:)``

## Overview

Expand All @@ -7,3 +7,7 @@
### SwiftUI integration

- ``Sharing/SharedReaderKey/fetchOne(sql:arguments:database:animation:)``

### Custom scheduling

- ``Sharing/SharedReaderKey/fetchOne(sql:arguments:database:scheduler:)``
6 changes: 3 additions & 3 deletions Sources/SharingGRDB/Documentation.docc/SharingGRDB.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,6 @@ with SQLite to take full advantage of GRDB and SharingGRDB.

### Fetch strategies

- ``Sharing/SharedReaderKey/fetchAll(sql:arguments:database:scheduler:)``
- ``Sharing/SharedReaderKey/fetchOne(sql:arguments:database:scheduler:)``
- ``Sharing/SharedReaderKey/fetch(_:database:scheduler:)-8kkig``
- ``Sharing/SharedReaderKey/fetchAll(sql:arguments:database:)``
- ``Sharing/SharedReaderKey/fetchOne(sql:arguments:database:)``
- ``Sharing/SharedReaderKey/fetch(_:database:)-3qcpd``
32 changes: 15 additions & 17 deletions Sources/SharingGRDB/FetchKey+SwiftUI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@
extension SharedReaderKey {
/// A key that can query for data in a SQLite database.
///
/// A version of ``Sharing/SharedReaderKey/fetch(_:database:scheduler:)-8kkig`` that can be
/// configured with a SwiftUI animation. See
/// ``Sharing/SharedReaderKey/fetch(_:database:scheduler:)-8kkig`` for more info on how to
/// use this API.
/// A version of ``Sharing/SharedReaderKey/fetch(_:database:)-3qcpd`` that can be configured
/// with a SwiftUI animation. See ``Sharing/SharedReaderKey/fetch(_:database:)-3qcpd`` for more
/// info on how to use this API.
///
/// - Parameters:
/// - request: A request describing the data to fetch.
Expand All @@ -28,10 +27,9 @@

/// A key that can query for a collection of data in a SQLite database.
///
/// A version of ``Sharing/SharedReaderKey/fetch(_:database:scheduler:)-8kkig`` that can be
/// configured with a SwiftUI animation. See
/// ``Sharing/SharedReaderKey/fetch(_:database:scheduler:)-8kkig`` for more info on how to
/// use this API.
/// A version of ``Sharing/SharedReaderKey/fetch(_:database:)-3qcpd`` that can be configured
/// with a SwiftUI animation. See ``Sharing/SharedReaderKey/fetch(_:database:)-3qcpd`` for more
/// info on how to use this API.
///
/// - Parameters:
/// - request: A request describing the data to fetch.
Expand All @@ -50,10 +48,10 @@

/// A key that can query for a collection of data in a SQLite database.
///
/// A version of ``Sharing/SharedReaderKey/fetchAll(sql:arguments:database:scheduler:)`` that
/// can be configured with a SwiftUI animation. See
/// ``Sharing/SharedReaderKey/fetchAll(sql:arguments:database:scheduler:)`` for more information
/// on how to use this API.
/// A version of ``Sharing/SharedReaderKey/fetchAll(sql:arguments:database:)`` that can be
/// configured with a SwiftUI animation. See
/// ``Sharing/SharedReaderKey/fetchAll(sql:arguments:database:)`` for more information on how to
/// use this API.
///
/// - Parameters:
/// - sql: A raw SQL string describing the data to fetch.
Expand All @@ -79,10 +77,10 @@

/// A key that can query for a value in a SQLite database.
///
/// A version of ``Sharing/SharedReaderKey/fetchOne(sql:arguments:database:scheduler:)`` that
/// can be configured with a SwiftUI animation. See
/// ``Sharing/SharedReaderKey/fetchAll(sql:arguments:database:scheduler:)`` for more information
/// on how to use this API.
/// A version of ``Sharing/SharedReaderKey/fetchOne(sql:arguments:database:)`` that can be
/// configured with a SwiftUI animation. See
/// ``Sharing/SharedReaderKey/fetchAll(sql:arguments:database:)`` for more information on how to
/// use this API.
///
/// - Parameters:
/// - sql: A raw SQL string describing the data to fetch.
Expand All @@ -107,7 +105,7 @@
}
}

private struct AnimatedScheduler: ValueObservationScheduler {
private struct AnimatedScheduler: ValueObservationScheduler, Hashable {
let animation: Animation
func immediateInitialValue() -> Bool { true }
func schedule(_ action: @escaping @Sendable () -> Void) {
Expand Down
Loading