feat: Begins breaking database out into it's own module, using dependencies
This commit is contained in:
30
Sources/DatabaseClient/Interface.swift
Normal file
30
Sources/DatabaseClient/Interface.swift
Normal file
@@ -0,0 +1,30 @@
|
||||
import Dependencies
|
||||
import DependenciesMacros
|
||||
import FluentKit
|
||||
|
||||
public extension DependencyValues {
|
||||
var database: DatabaseClient {
|
||||
get { self[DatabaseClient.self] }
|
||||
set { self[DatabaseClient.self] = newValue }
|
||||
}
|
||||
}
|
||||
|
||||
@DependencyClient
|
||||
public struct DatabaseClient: Sendable {
|
||||
public var employees: Employees
|
||||
public var migrations: @Sendable () async throws -> [any AsyncMigration]
|
||||
public var purchaseOrders: PurchaseOrders
|
||||
public var users: Users
|
||||
public var vendorBranches: VendorBranches
|
||||
public var vendors: Vendors
|
||||
}
|
||||
|
||||
extension DatabaseClient: TestDependencyKey {
|
||||
public static let testValue: DatabaseClient = Self(
|
||||
employees: .testValue,
|
||||
purchaseOrders: .testValue,
|
||||
users: .testValue,
|
||||
vendorBranches: .testValue,
|
||||
vendors: .testValue
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user