Skip to content

Add ObservableQuery to reduce GRDBQuery dependency#1689

Open
DRadmir wants to merge 10 commits intomainfrom
observable-query
Open

Add ObservableQuery to reduce GRDBQuery dependency#1689
DRadmir wants to merge 10 commits intomainfrom
observable-query

Conversation

@DRadmir
Copy link
Contributor

@DRadmir DRadmir commented Feb 9, 2026

Introduce custom query observation system:

  • Add ObservableQuery generic wrapper for reactive database queries
  • Add DatabaseQueryable protocol (replaces ValueObservationQueryable)
  • Add DatabaseAccess environment key for database injection
  • Add QueryBindingModifier with .bindQuery() view modifier

Migrate TransactionsRequest and related ViewModels to new system:

  • TransactionsFilterViewModel, TransactionsViewModel

  • AssetSceneViewModel, PerpetualSceneViewModel

  • Test

Introduce custom query observation system:
- Add ObservableQuery generic wrapper for reactive database queries
- Add DatabaseQueryable protocol (replaces ValueObservationQueryable)
- Add DatabaseAccess environment key for database injection
- Add QueryBindingModifier with .bindQuery() view modifier

Migrate TransactionsRequest and related ViewModels to new system:
- TransactionsFilterViewModel, TransactionsViewModel
- AssetSceneViewModel, PerpetualSceneViewModel
@DRadmir DRadmir self-assigned this Feb 9, 2026
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @DRadmir, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request refactors the application's data observation layer by introducing a custom, more integrated system for reactive database queries. The primary goal is to reduce reliance on the external GRDBQuery library, offering a more streamlined and controlled approach to observing database changes. This change impacts how transaction-related data is fetched and observed across various parts of the application, leading to a more consistent and potentially more performant data flow.

Highlights

  • New Query Observation System: Introduced a custom query observation system with ObservableQuery as a generic wrapper for reactive database queries, reducing direct dependency on GRDBQuery.
  • Protocol Refinement: Defined a new DatabaseQueryable protocol, which replaces the ValueObservationQueryable protocol for database query definitions.
  • Database Injection: Added a DatabaseAccess environment key and a .databaseQueue() view modifier for injecting the DatabaseQueue into the SwiftUI environment.
  • View Modifier for Query Binding: Implemented QueryBindingModifier and a .bindQuery() view modifier to easily bind ObservableQuery instances to SwiftUI views.
  • ViewModel Migration: Migrated TransactionsRequest and several ViewModels, including AssetSceneViewModel, PerpetualSceneViewModel, TransactionsFilterViewModel, and TransactionsViewModel, to utilize the new query observation system.

🧠 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
  • Features/Assets/Sources/ViewModels/AssetSceneViewModel.swift
    • Imported the Store module.
    • Replaced the transactions array with an ObservableQuery<TransactionsRequest> property.
    • Initialized transactionsQuery in the init method.
    • Updated BalanceType to Primitives.BalanceType for consistency.
  • Features/Perpetuals/Sources/ViewModels/PerpetualSceneViewModel.swift
    • Replaced transactionsRequest with an ObservableQuery<TransactionsRequest> property.
    • Initialized transactionsQuery in the init method.
    • Converted transactions into a computed property that derives its value from transactionsQuery.value.
  • Features/Transactions/Sources/Scenes/TransactionsScene.swift
    • Removed the GRDBQuery import, reflecting the shift away from its direct use.
  • Features/Transactions/Sources/ViewModels/TransactionsFilterViewModel.swift
    • Modified didSet observers for chainsFilter and transactionTypesFilter to update query.request.filters.
    • Replaced the request property with an ObservableQuery<TransactionsRequest> property named query.
    • Initialized the new query property in the init method.
  • Features/Transactions/Sources/ViewModels/TransactionsViewModel.swift
    • Changed the transactions property to be a computed property, fetching its value from filterModel.query.value.
  • Gem/Navigation/Assets/AssetNavigationView.swift
    • Replaced the .observeQuery modifier for transactions with the new .bindQuery(model.transactionsQuery).
  • Gem/Navigation/Perpetuals/PerpetualNavigationView.swift
    • Replaced the .observeQuery modifier for transactions with the new .bindQuery(model.transactionsQuery).
  • Gem/Navigation/Transactions/TransactionsNavigationStack.swift
    • Replaced the .observeQuery modifier for transaction filters with the new .bindQuery(model.filterModel.query).
  • Gem/Services/AppResolver+ViewInjection.swift
    • Imported the Store module.
    • Added a .databaseQueue(storages.db.dbQueue) environment modifier for database injection.
    • Included a TODO comment to remove the databaseContext once all requests are migrated.
  • Packages/Store/Sources/Query/BindableQuery.swift
    • New file: Introduced BindableQuery protocol for objects that can bind to a database queue.
  • Packages/Store/Sources/Query/DatabaseAccess.swift
    • New file: Defined DatabaseAccess struct and an extension on View to provide a databaseQueue environment modifier for injecting DatabaseQueue.
  • Packages/Store/Sources/Query/DatabaseQueryable.swift
    • New file: Introduced DatabaseQueryable protocol, which defines the requirements for a query that can fetch a value from a database.
  • Packages/Store/Sources/Query/ObservableQuery.swift
    • New file: Implemented ObservableQuery, a generic @Observable class that wraps a DatabaseQueryable request and provides reactive observation of its value.
  • Packages/Store/Sources/Query/QueryBindingModifier.swift
    • New file: Created QueryBindingModifier and a bindQuery extension on View to facilitate binding BindableQuery instances to the view lifecycle.
  • Packages/Store/Sources/Requests/TransactionsRequest.swift
    • Updated TransactionsRequest to conform to the new DatabaseQueryable protocol instead of ValueObservationQueryable.
    • Removed GRDBQuery and Combine imports as they are no longer directly used here.
Activity
  • The pull request introduces a new custom query observation system, moving away from the GRDBQuery dependency.
  • New protocols (BindableQuery, DatabaseQueryable) and classes (ObservableQuery, DatabaseAccess, QueryBindingModifier) have been added to support this system.
  • Existing ViewModels and UI components related to transactions have been refactored to integrate with the new ObservableQuery and .bindQuery() mechanism.
  • Environment injection for the database queue has been updated to use the new DatabaseAccess.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a 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 well-designed custom query observation system, effectively reducing the dependency on GRDBQuery. The new ObservableQuery wrapper and DatabaseQueryable protocol provide a clean, reactive way to handle database queries. The migration of existing view models and views to this new system is thorough and improves the overall architecture. I have one suggestion for improving consistency in the TransactionsFilterViewModel.

DRadmir and others added 6 commits February 11, 2026 12:11
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
  - Remove bindQuery modifier in favor of unified onChangeBindQuery
  - Remove AssetData.empty and ChainAssetData.empty, use with(asset:) pattern
  - Inline all ObservableQuery initializations to single lines
  - Move transactionsQuery and isPresentingToastMessage to MainTabViewModel
  - Fix duplicate Store imports in test files
  - Simplify test mocks by reusing model instances
@DRadmir DRadmir requested a review from gemcoder21 February 13, 2026 09:19
gemcoder21 and others added 2 commits February 13, 2026 21:58
…e-query

# Conflicts:
#	Features/Perpetuals/Sources/ViewModels/PerpetualSceneViewModel.swift
#	Features/Swap/Sources/Scenes/SwapScene.swift
#	Features/Swap/Tests/SwapTests/SwapSceneViewModelTests.swift
#	Features/WalletTab/Sources/ViewModels/WalletSceneViewModel.swift
#	Packages/Store/Sources/Requests/TotalValueRequest.swift
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.

2 participants