Skip to content
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

Migrating To GRDBQuery 0.9 #152

Merged
merged 11 commits into from
Sep 12, 2024
1 change: 1 addition & 0 deletions Gem/App.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ struct GemApp: App {
WalletCoordinator(
db: db
)
.databaseContext(.readWrite { db.dbQueue })
.navigationBarTitleDisplayMode(.inline)
.tint(Colors.blue)
}
Expand Down
3 changes: 1 addition & 2 deletions Gem/Connections/Scenes/ConnectionsScene.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ struct ConnectionsScene: View {
@State private var isPresentingScanner: Bool = false
@State private var isPresentingErrorMessage: String?

@Query<ConnectionsRequest>
@Query(ConnectionsRequest())
gemdev111 marked this conversation as resolved.
Show resolved Hide resolved
var connections: [WalletConnection]

var groupedByWallet: [Wallet: [Primitives.WalletConnection]] {
Expand All @@ -32,7 +32,6 @@ struct ConnectionsScene: View {
model: ConnectionsViewModel
) {
self.model = model
_connections = Query(ConnectionsRequest(), in: \.db.dbQueue)
}

var body: some View {
Expand Down
2 changes: 2 additions & 0 deletions Gem/Wallet/Types/Environment.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import Store
import Keystore
import GemstonePrimitives

// TODO: - remove ref. https://swiftpackageindex.com/groue/grdbquery/0.9.0/documentation/grdbquery/migratingtogrdbquery09-unrestricted-writes
struct DatabaseQueueKey: EnvironmentKey {
static var defaultValue: DB { DB.main }
}
Expand Down Expand Up @@ -80,6 +81,7 @@ struct IsWalletPresentedServiceKey: EnvironmentKey {
}

extension EnvironmentValues {
// TODO: - remove ref. https://swiftpackageindex.com/groue/grdbquery/0.9.0/documentation/grdbquery/migratingtogrdbquery09-unrestricted-writes
var db: DB {
get { self[DatabaseQueueKey.self] }
set { self[DatabaseQueueKey.self] = newValue }
Expand Down
14 changes: 3 additions & 11 deletions Packages/Store/Sources/Requests/ConnectionsRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,13 @@ import GRDBQuery
import Combine
import Primitives

public struct ConnectionsRequest: Queryable {
public struct ConnectionsRequest: ValueObservationQueryable {
public static var defaultValue: [WalletConnection] { [] }

public init() {
}

public func publisher(in dbQueue: DatabaseQueue) -> AnyPublisher<[WalletConnection], Error> {
ValueObservation
.tracking { db in try fetch(db) }
.publisher(in: dbQueue, scheduling: .immediate)
.map { $0.map{ $0 } }
.eraseToAnyPublisher()
}

private func fetch(_ db: Database) throws -> [WalletConnection] {

public func fetch(_ db: Database) throws -> [WalletConnection] {
return try WalletRecord
.including(required: WalletRecord.connection)
.asRequest(of: WalletConnectionInfo.self)
Expand Down
Loading