Skip to content

Add CoreModel 2.8.0 database function support#1

Merged
colemancda merged 9 commits into
masterfrom
feature/database-functions
Jul 17, 2026
Merged

Add CoreModel 2.8.0 database function support#1
colemancda merged 9 commits into
masterfrom
feature/database-functions

Conversation

@colemancda

Copy link
Copy Markdown
Member

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 over AttributeValues). 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 CoreModel 2.8.0.
  • Predicate.swift — the Expression.function case is untranslatable to a Mongo query, so it returns nil (falls back to the in-memory path).
  • FetchRequest.swiftSortDescriptor now stores a term (.property / .function); the server-side sort document only emits .property terms.
  • FunctionEvaluation.swift (new) — in-memory predicate evaluation and sorting that invoke registered functions, ported from CoreModel's CoreData backend.
  • MongoDatabase.swiftMongoModelStorage now implements the new required register(function:) protocol method, keeps a function registry, and routes fetch/count/fetchID through an in-memory path when the request references a function. Also marks MongoDatabase retroactively Sendable, matching the existing pattern for MongoCollectionOptions.

Tests

  • TestModel.swift — nested value types are marked Sendable (required now that Entity: Sendable).
  • LegacyCodable/ — vendors CoreModel's Codable-to-ModelData bridge, which 2.8.0 moved out of the library into its own test target; restores the default Entity conformance 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.

@colemancda
colemancda merged commit 06b20b8 into master Jul 17, 2026
1 check passed
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.

1 participant