-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConfig.swift
More file actions
49 lines (39 loc) · 1.34 KB
/
Config.swift
File metadata and controls
49 lines (39 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
//
// Config.swift
// PureSQL
//
// Created by Wes Wickwire on 8/5/25.
//
import Foundation
import Yams
public struct Config: Codable {
public let queries: String
public let migrations: String
public let output: String?
public let databaseName: String?
public let additionalImports: [String]?
public let tableNamePattern: String?
struct NotFoundError: Error, CustomStringConvertible {
var description: String { "Config does not exist" }
}
public init(at path: String) throws {
var url = URL(fileURLWithPath: path)
if url.lastPathComponent != "puresql.yaml" {
url.appendPathComponent("puresql.yaml")
}
guard FileManager.default.fileExists(atPath: url.path) else {
throw NotFoundError()
}
let data = try Data(contentsOf: url)
let decoder = YAMLDecoder()
self = try decoder.decode(Config.self, from: data)
}
public func project(at path: String) -> Project {
let url = URL(fileURLWithPath: path)
return Project(
generatedOutputFile: url.appendingPathComponent(output ?? "Queries.swift"),
migrationsDirectory: url.appendingPathComponent(migrations),
queriesDirectory: url.appendingPathComponent(queries)
)
}
}