Add in-memory store and filtering engine - #26
Merged
Conversation
Code Coverage OverviewLanguages: Swift Swift / code-coverage/llvm-covThe overall coverage in commit 97f1ff2 in the Show a code coverage summary of the most impacted files.
Updated |
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
Adds a pure Swift in-memory store and filtering engine to the
CoreModeltarget, compatible with Embedded Swift and platforms without Foundation.Predicateevaluation engine (Predicate/Evaluate.swift): evaluates anyFetchRequest.Predicateagainst aModelDatainstance in memory — comparisons (including cross-numeric-type equality and ordering), compound predicates, string operators (BEGINSWITH,ENDSWITH,CONTAINS,IN,LIKEvia a pure Swift wildcard matcher,MATCHESwhere Foundation regex support is available), relationship comparisons (CONTAINS/INon to-many, identifier equality on to-one,ANY/ALLmodifiers), and customDatabaseFunctionexpressions.FetchRequestin-memory execution (FetchRequestEvaluation.swift): filters by entity and predicate, sorts by sort descriptors (property and function terms, stable identifier tiebreaker), and applies fetch offset/limit. Publicfiltered(by:)/sorted(by:)helpers on[ModelData].InMemoryModelStorage(InMemoryStore.swift): an actor-backedModelStoragethat keeps all objects in memory and evaluates fetch requests with the new engine, validating every operation's entity against a requiredModelschema. Uses typed throws (CoreModelError) so it also compiles under Embedded Swift, where the untyped-throwsprotocol conformance is unavailable and the same API is called directly.NSManagedObjectContextdelegates to the public CoreModel engine.Testing
swift test: 93 tests pass, including 25 new tests covering predicate evaluation, sorting, fetch request execution, and the in-memory store (CRUD, batch operations, predicates, custom functions, schema validation).swift build(macOS),swift build --swift-sdk wasm, andSWIFT_EMBEDDED=1 swift build --swift-sdk wasm-embeddedall succeed.