feat: Begins breaking database out into it's own module, using dependencies

This commit is contained in:
2025-01-13 14:39:37 -05:00
parent 540b3e771a
commit 217dc5fa56
20 changed files with 1372 additions and 16 deletions

View File

@@ -0,0 +1,55 @@
import Dependencies
import DependenciesMacros
import SharedModels
public extension DatabaseClient {
@DependencyClient
struct Vendors: Sendable {
public var create: @Sendable (Vendor.Create) async throws -> Vendor
public var delete: @Sendable (Vendor.ID) async throws -> Void
public var fetchAll: @Sendable (FetchRequest) async throws -> [Vendor]
public var get: @Sendable (Vendor.ID, GetRequest) async throws -> Vendor?
public var update: @Sendable (Vendor.ID, Vendor.Update) async throws -> Vendor
public enum FetchRequest {
case all
case withBranches
}
public enum GetRequest {
case all
case withBranches
}
public func fetchAll() async throws -> [Vendor] {
try await fetchAll(.all)
}
public func get(_ id: Vendor.ID) async throws -> Vendor? {
try await get(id, .all)
}
}
}
extension DatabaseClient.Vendors: TestDependencyKey {
public static let testValue: DatabaseClient.Vendors = Self()
}
public extension Vendor {
struct Create: Codable, Sendable {
public let name: String
public init(name: String) {
self.name = name
}
}
struct Update: Codable, Sendable {
public let name: String?
public init(name: String?) {
self.name = name
}
}
}