-
Notifications
You must be signed in to change notification settings - Fork 65
Custom SQLiteDatabase Implementations #664
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
Merged
calvincestari
merged 1 commit into
apollographql:main
from
ChrisLaganiere:claganiere/extendible-SQLiteDatabase
Jun 4, 2025
Merged
Custom SQLiteDatabase Implementations #664
calvincestari
merged 1 commit into
apollographql:main
from
ChrisLaganiere:claganiere/extendible-SQLiteDatabase
Jun 4, 2025
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
Add public initializer that would enable a custom SQLiteDatabase implementation
👷 Deploy request for apollo-ios-docc pending review.Visit the deploys page to approve it
|
✅ Docs preview has no changesThe preview was not built because there were no changes. Build ID: e1dc8528829c91c4fbc56a0b |
by the way, super excited for #615! |
AnthonyMDev
approved these changes
Jun 4, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the detailed write-up on the use case here. I'm open to accepting this PR.
BobaFetters
approved these changes
Jun 4, 2025
BobaFetters
pushed a commit
that referenced
this pull request
Jun 4, 2025
BobaFetters
pushed a commit
to apollographql/apollo-ios
that referenced
this pull request
Jun 4, 2025
BobaFetters
pushed a commit
that referenced
this pull request
Jun 4, 2025
b0007f91 Custom SQLiteDatabase Implementations (#664) git-subtree-dir: apollo-ios git-subtree-split: b0007f917ae773fdaf4fe8222a324230eb2affe5
BobaFetters
pushed a commit
that referenced
this pull request
Jun 4, 2025
git-subtree-dir: apollo-ios git-subtree-mainline: 945b418 git-subtree-split: b0007f917ae773fdaf4fe8222a324230eb2affe5
Thanks for your help! |
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.
Add a public initializer to
DatabaseRow
to enable customSQLiteDatabase
implementationsBackground
The
SQLiteNormalizedCache
is nicely structured with protocols so that consumers of the library can implement their own components under the hood if they choose to. There are a couple reasons one might want to do this:The Problem
All of that is possible! ...almost
The use of
SQLiteDatabase
protocol makes it easy to implement and inject your own implementation, with one blocking exception. The missing piece is a public initializer forDatabaseRow
, a type returned by one of the methods:apollo-ios-dev/apollo-ios/Sources/ApolloSQLite/SQLiteDatabase.swift
Line 37 in aad10ca
If I as a consumer try to implement the public
SQLiteDatabase
protocol, I am blocked by this method, because I cannot instantiateDatabaseRow
values. The default, automatic memberwise initializer for any Swift struct is internal, meaning that consumers of a library cannot use it, and get an error if trying to instantiate:The change here, to add an explicit
public init
to this struct type, is all that is needed to enable custom SQLite implementations, as the original PR from 2021 seems to have intended. This change would allow me to implement the custom TTL policy on my own Apollo cacheTesting
There is no imperative logic change here to test. The best way to unit test this would be to add a full custom SQLiteDatabase implementation to the test suite, which I am happy to do, but seemed like a larger change. Risk here is low, so I skipped doing that for now
Alternatives
I could implement an entire
NormalizedCache
, possibly copying lots of code already in the repo. That is possible, but it would be much easier to allow flexibility with the utilities already provided by the sdk, by making this small change