Skip to content
This repository was archived by the owner on Mar 26, 2026. It is now read-only.

Commit 39f7163

Browse files
committed
Remove defaultValue from DatabaseQueryable protocol
1 parent f0842dd commit 39f7163

9 files changed

Lines changed: 20 additions & 23 deletions

File tree

Features/Assets/Sources/ViewModels/AssetSceneViewModel.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public final class AssetSceneViewModel: Sendable {
6969
assetData: AssetData.with(asset: input.asset),
7070
feeAssetData: AssetData.with(asset: input.asset.chain.asset)
7171
)
72-
self.transactionsQuery = ObservableQuery(input.transactionsRequest)
72+
self.transactionsQuery = ObservableQuery(input.transactionsRequest, initialValue: [])
7373
self.isPresentingSelectedAssetInput = isPresentingSelectedAssetInput
7474
}
7575

Features/Perpetuals/Sources/ViewModels/PerpetualSceneViewModel.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public final class PerpetualSceneViewModel {
7575
type: .asset(assetId: asset.id),
7676
filters: [.types(transactionTypes.map { $0.rawValue })]
7777
)
78-
self.transactionsQuery = ObservableQuery(transactionsRequest)
78+
self.transactionsQuery = ObservableQuery(transactionsRequest, initialValue: [])
7979
}
8080

8181
public var navigationTitle: String {

Features/Transactions/Sources/ViewModels/TransactionsFilterViewModel.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public final class TransactionsFilterViewModel {
4646
type: type,
4747
filters: defaultFilters + [.types(transactionTypes.map { $0.rawValue })]
4848
)
49-
self.query = ObservableQuery(request)
49+
self.query = ObservableQuery(request, initialValue: [])
5050
}
5151

5252
public var isAnyFilterSpecified: Bool {

Packages/Store/Sources/Query/BindableQuery.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ import Foundation
44
import GRDB
55

66
public protocol BindableQuery: AnyObject, Sendable {
7-
@MainActor func bind(db: DatabaseQueue)
7+
@MainActor func bind(dbQueue: DatabaseQueue)
88
}

Packages/Store/Sources/Query/DatabaseAccess.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,19 @@ import SwiftUI
55
import GRDB
66

77
public struct DatabaseAccess: Sendable {
8-
private let dbQueue: DatabaseQueue?
8+
private let _dbQueue: DatabaseQueue?
99

1010
public static let notConfigured = DatabaseAccess(nil)
1111

1212
public init(_ dbQueue: DatabaseQueue?) {
13-
self.dbQueue = dbQueue
13+
self._dbQueue = dbQueue
1414
}
1515

16-
public var db: DatabaseQueue {
17-
guard let dbQueue else {
16+
public var dbQueue: DatabaseQueue {
17+
guard let _dbQueue else {
1818
fatalError("DatabaseQueue not configured. Use .databaseQueue() modifier.")
1919
}
20-
return dbQueue
20+
return _dbQueue
2121
}
2222
}
2323

@@ -33,7 +33,7 @@ public extension EnvironmentValues {
3333
}
3434

3535
public extension View {
36-
func databaseQueue(_ db: DatabaseQueue) -> some View {
37-
environment(\.database, DatabaseAccess(db))
36+
func databaseQueue(_ dbQueue: DatabaseQueue) -> some View {
37+
environment(\.database, DatabaseAccess(dbQueue))
3838
}
3939
}

Packages/Store/Sources/Query/DatabaseQueryable.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,5 @@ import GRDB
55

66
public protocol DatabaseQueryable: Equatable, Sendable {
77
associatedtype Value: Equatable & Sendable
8-
@MainActor static var defaultValue: Value { get }
98
func fetch(_ db: Database) throws -> Value
109
}

Packages/Store/Sources/Query/ObservableQuery.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,27 +18,27 @@ public final class ObservableQuery<Request: DatabaseQueryable>: Sendable, Bindab
1818

1919
public private(set) var value: Request.Value
2020

21-
private var db: DatabaseQueue?
21+
private var dbQueue: DatabaseQueue?
2222
private var cancellable: AnyCancellable?
2323

24-
public init(_ request: Request) {
24+
public init(_ request: Request, initialValue: Request.Value) {
2525
self.request = request
26-
self.value = Request.defaultValue
26+
self.value = initialValue
2727
}
2828

29-
public func bind(db: DatabaseQueue) {
30-
guard self.db == nil else { return }
31-
self.db = db
29+
public func bind(dbQueue: DatabaseQueue) {
30+
guard self.dbQueue == nil else { return }
31+
self.dbQueue = dbQueue
3232
startObservation()
3333
}
3434

3535
private func startObservation() {
36-
guard let db else { return }
36+
guard let dbQueue else { return }
3737

3838
cancellable = ValueObservation.tracking { [request] db in
3939
try request.fetch(db)
4040
}
41-
.publisher(in: db, scheduling: .immediate)
41+
.publisher(in: dbQueue, scheduling: .immediate)
4242
.sink(
4343
receiveCompletion: { completion in
4444
if case .failure(let error) = completion {

Packages/Store/Sources/Query/QueryBindingModifier.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ struct QueryBindingModifier: ViewModifier {
1212
content
1313
.onAppear {
1414
for query in queries {
15-
query.bind(db: database.db)
15+
query.bind(dbQueue: database.dbQueue)
1616
}
1717
}
1818
}

Packages/Store/Sources/Requests/TransactionsRequest.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ import GRDB
55
import Primitives
66

77
public struct TransactionsRequest: DatabaseQueryable {
8-
public static var defaultValue: [TransactionExtended] { [] }
9-
108
private let walletId: WalletId
119
private let type: TransactionsRequestType
1210
private let limit: Int

0 commit comments

Comments
 (0)