Skip to content

Conversation

@johnclayton
Copy link
Member

  1. Observable fetch wrappers

Added property wrappers that automatically update when data matching a query changes:

  • FetchFirst - Tracks first result matching a query
  • FetchAll - Tracks all results matching a query
  • FetchResults - Tracks results as lazy collection with batch size
  1. Relationship prefetching

Added prefetchRelationship() to reduce database trips when accessing related objects and support fetch wrappers returning a larger portion of the graph.

  1. Fetch specific properties

Added fetchKeyPaths() to fetch only specific properties, which can improve performance for a given fetch.

@johnclayton johnclayton self-assigned this Aug 12, 2025
import CoreData
import Dependencies
import SwiftData
#if canImport(SwiftUI)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't need this anymore

}
}

#if canImport(SwiftUI)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not needed with Observable

import CoreData
import Dependencies
import SwiftData
#if canImport(SwiftUI)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove

}
}

#if canImport(SwiftUI)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove

/// A range representing the number of results to skip before returning matches and maximum number of results to fetch. When `nil`, the query will return all matching results.
public var range: Range<Int>?

public var relationshipKeyPaths: [PartialKeyPath<T>] = []
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

documentation

/// .prefetchRelationship(\.customer)
/// .prefetchRelationship(\.items)
/// ```
func prefetchRelationship(_ keyPath: PartialKeyPath<T>) -> Self {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This really should work the way prefetchKeyPaths() does and take a variadic list of keypaths.

@johnclayton johnclayton merged commit 1f9d975 into main Aug 12, 2025
1 check passed
@johnclayton johnclayton deleted the fetch-wrappers branch August 12, 2025 19:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants