Skip to content

Commit

Permalink
Merge pull request #7 from hsharghi/async
Browse files Browse the repository at this point in the history
Fix import a FluentPostgresDriver without checking
  • Loading branch information
hsharghi authored Jun 20, 2023
2 parents 3890977 + 5fbd025 commit b438cd9
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions Sources/VaporWallet/WalletRepository.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@

import Vapor
import Fluent
#if canImport(FluentPostgresDriver)
import FluentPostgresDriver
#endif

/// This calss gives access to wallet methods for a `HasWallet` model.
/// Creating multiple wallets, accessing them and getting balance of each wallet,
Expand Down Expand Up @@ -75,6 +77,7 @@ extension WalletsRepository {
if withUnconfirmed {
// (1) Temporary workaround for sum and average aggregates,
var balance: Double
#if canImport(FluentPostgresDriver)
if let _ = self.db as? PostgresDatabase {
let balanceOptional = try? await wallet.$transactions
.query(on: self.db)
Expand All @@ -88,6 +91,13 @@ extension WalletsRepository {

balance = intBalance == nil ? 0.0 : Double(intBalance!)
}
#else
let intBalance = try await wallet.$transactions
.query(on: self.db)
.sum(\.$amount)

balance = intBalance == nil ? 0.0 : Double(intBalance!)
#endif
return asDecimal ? balance.toDecimal(with: wallet.decimalPlaces) : balance
}
return asDecimal ? Double(wallet.balance).toDecimal(with: wallet.decimalPlaces) : Double(wallet.balance)
Expand Down

0 comments on commit b438cd9

Please sign in to comment.