-
Notifications
You must be signed in to change notification settings - Fork 667
dataconnect: caching: add sqlite database logic #7720
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
base: main
Are you sure you want to change the base?
Conversation
… later): `insertQueryResult() should merge entities with different data`
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. |
📝 PRs merging into main branchOur main branch should always be in a releasable state. If you are working on a larger change, or if you don't want this change to see the light of the day just yet, consider using a feature branch first, and only merge into the main branch when the code complete and ready to be released. |
|
/gemini review |
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.
Code Review
This pull request introduces a significant and well-implemented feature: an offline caching layer for Data Connect using SQLite. The code is well-structured, with a clear separation of concerns for database opening, migration, and caching logic. The use of coroutines with a single-threaded dispatcher for writes ensures thread safety and prevents database locking issues. The state management within DataConnectCacheDatabase is robust, and the graceful shutdown logic is well-handled. The addition of comprehensive property-based tests is commendable and greatly increases confidence in the new functionality. I have only a couple of minor suggestions regarding log messages. Overall, this is an excellent contribution.
...taconnect/src/main/kotlin/com/google/firebase/dataconnect/sqlite/DataConnectCacheDatabase.kt
Outdated
Show resolved
Hide resolved
...t/src/main/kotlin/com/google/firebase/dataconnect/sqlite/DataConnectCacheDatabaseMigrator.kt
Outdated
Show resolved
Hide resolved
|
/gemini summary |
Summary of ChangesThis pull request lays the groundwork for Firebase Data Connect's offline caching capabilities by integrating SQLite. It introduces a robust, thread-safe database layer that manages cached query results and associated entities, complete with schema migration, secure database opening, and a suite of utility functions to streamline database interactions. The changes ensure reliable and performant data persistence for offline scenarios. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
|
This PR adds a sqlite database layer to
firebase-dataconnectthat manages cached query results and associated entities, complete with schema migration, secure database opening, and a suite of utility functions to streamline database interactions.Highlights
DataConnectCacheDatabaseclass is designed to be thread-safe, utilizing Kotlin coroutines and a single-threaded dispatcher to manage write transactions, preventingSQLITE_BUSYerrors and ensuring ordered execution.DataConnectCacheDatabaseMigratoris included to handle database initialization and schema migrations, ensuring data integrity and compatibility across different versions. It also manages the SQLiteapplication_idanduser_versionpragmas.SQLiteDatabase(SQLiteDatabaseExts) and aSQLiteStatementBuildersimplify common database operations, improve SQL logging, and provide a more robust way to construct parameterized queries.ImmutableByteArrayfor safe handling of byte arrays andSemanticVersionfor structured version comparison and encoding, along withStringUtilfor various string manipulations.Changelog
DataConnectCacheDatabaseclass, the core component for managing cached query results and entities in SQLite.initialize()andclose()methods for lifecycle management of the database.getQueryResult()andinsertQueryResult()for retrieving and storing query data and associated entities.DataConnectCacheDatabaseMigratorfor handling database schema creation and versioning.application_idanduser_versionpragmas to ensure database integrity and compatibility.DataConnectSQLiteDatabaseOpenerto configure and open SQLite databases.SQLiteDatabaseto provide simplifiedexecSQLandrawQuerymethods.application_idandlast_insert_rowid.SQLiteStatementBuilderfor constructing SQL statements with automatic and re-usable binding numbering.ImmutableByteArrayas a wrapper forByteArrayto enforce immutability and provide safe handling.SemanticVersiondata class for representing and comparing semantic versions, including encoding to and decoding from integers.StringUtilobject with utility functions for hexadecimal string conversion and middle ellipsizing.DataConnectCacheDatabaseMigrator, verifying correct application ID and schema migration behavior.DataConnectCacheDatabase, covering initialization, closing, and the insertion and retrieval of query results with and without entities.DataConnectSQLiteDatabaseOpener, ensuring correct database opening, file creation, and configuration settings.QueryResultArbto includeEntityRepeatPolicyfor more flexible generation of test data, allowing for repeated or mutated entities across samples.SQLiteArbsto provide Kotest arbitrary data generators for various SQLite column values, including nulls, integers, floats, doubles, strings, and byte arrays, with edge case handling.SQLiteArbsto validate the generation of diverse SQLite column values and their edge cases.SQLiteDatabaseExts, covering SQL execution, query logging, and application ID management, ensuring correct behavior and logging output.semanticVersionarbitrary generator for Kotest property testing.ImmutableByteArray, verifying its immutability, equality, and utility methods.SemanticVersion, covering its encoding, decoding, and comparison logic.StringUtil, verifying hexadecimal conversion for integers and byte arrays, and string ellipsizing functionality.SQLiteDatabaseRule, a JUnit test rule for creating and managing SQLite databases (in-memory or file-based) for testing purposes.StringCaseInsensitiveEquality, a KotestEqualityimplementation for case-insensitive string comparisons in tests.containLoneSurrogate()andshouldNotContainLoneSurrogates()for verifying Unicode string integrity in tests.listNoRepeatarbitrary generator for Kotest, ensuring generated lists contain no repeated elements.OffsetLengthOutOfRangeArbfor generating arbitrary offset and length values that are intentionally out of bounds for array access, useful for testing error handling.OffsetLengthOutOfRangeArbto verify its ability to generate out-of-range offset and length values.