Add CoreModel 2.8.0 database function support#1
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Updates the CoreModel dependency to 2.8.0 and implements the new custom database function API introduced in CoreModel PR #22.
CoreModel 2.8.0 lets predicates and sort descriptors reference custom
DatabaseFunctions (arbitrary Swift closures overAttributeValues). Since MongoDB cannot execute those closures server-side, this backend mirrors the CoreData backend's strategy: fetch a native superset with function comparisons stripped from the predicate, then filter, sort, and paginate in memory.Changes
Package.swift— require CoreModel2.8.0.Predicate.swift— theExpression.functioncase is untranslatable to a Mongo query, so it returnsnil(falls back to the in-memory path).FetchRequest.swift—SortDescriptornow stores aterm(.property/.function); the server-side sort document only emits.propertyterms.FunctionEvaluation.swift(new) — in-memory predicate evaluation and sorting that invoke registered functions, ported from CoreModel's CoreData backend.MongoDatabase.swift—MongoModelStoragenow implements the new requiredregister(function:)protocol method, keeps a function registry, and routesfetch/count/fetchIDthrough an in-memory path when the request references a function. Also marksMongoDatabaseretroactivelySendable, matching the existing pattern forMongoCollectionOptions.Tests
TestModel.swift— nested value types are markedSendable(required now thatEntity: Sendable).LegacyCodable/— vendors CoreModel's Codable-to-ModelDatabridge, which 2.8.0 moved out of the library into its own test target; restores the defaultEntityconformance for the hand-written Codable test models.The library builds cleanly and the test target compiles. The integration tests require a live MongoDB at
localhost:27017(provided via Docker in CI) and were not executed locally.