|
1 |
| -extension DatabaseConfigurationFactory { |
2 |
| - public static func postgres( |
3 |
| - url: URL, |
4 |
| - maxConnectionsPerEventLoop: Int = 1 |
5 |
| - ) throws -> DatabaseConfigurationFactory { |
6 |
| - guard let configuration = PostgresConfiguration(url: url) else { |
7 |
| - throw FluentPostgresError.invalidURL(url) |
8 |
| - } |
9 |
| - return .postgres( |
10 |
| - configuration: configuration, |
11 |
| - maxConnectionsPerEventLoop: maxConnectionsPerEventLoop |
12 |
| - ) |
13 |
| - } |
14 |
| - |
15 |
| - public static func postgres( |
16 |
| - hostname: String, |
17 |
| - port: Int = 5432, |
18 |
| - username: String, |
19 |
| - password: String, |
20 |
| - database: String? = nil, |
21 |
| - tlsConfiguration: TLSConfiguration? = nil, |
22 |
| - maxConnectionsPerEventLoop: Int = 1 |
23 |
| - ) -> DatabaseConfigurationFactory { |
24 |
| - return .postgres( |
25 |
| - configuration: .init( |
26 |
| - hostname: hostname, |
27 |
| - port: port, |
28 |
| - username: username, |
29 |
| - password: password, |
30 |
| - database: database, |
31 |
| - tlsConfiguration: tlsConfiguration |
32 |
| - ), |
33 |
| - maxConnectionsPerEventLoop: maxConnectionsPerEventLoop |
34 |
| - ) |
35 |
| - } |
36 |
| - |
37 |
| - public static func postgres( |
38 |
| - configuration: PostgresConfiguration, |
39 |
| - maxConnectionsPerEventLoop: Int = 1 |
40 |
| - ) -> DatabaseConfigurationFactory { |
41 |
| - return DatabaseConfigurationFactory { |
42 |
| - FluentPostgresConfiguration( |
43 |
| - middleware: [], |
44 |
| - configuration: configuration, |
45 |
| - maxConnectionsPerEventLoop: maxConnectionsPerEventLoop |
46 |
| - ) |
47 |
| - } |
48 |
| - } |
49 |
| -} |
50 |
| - |
51 |
| -struct FluentPostgresConfiguration: DatabaseConfiguration { |
52 |
| - var middleware: [AnyModelMiddleware] |
53 |
| - let configuration: PostgresConfiguration |
54 |
| - let maxConnectionsPerEventLoop: Int |
55 |
| - |
56 |
| - func makeDriver(for databases: Databases) -> DatabaseDriver { |
57 |
| - let db = PostgresConnectionSource( |
58 |
| - configuration: configuration |
59 |
| - ) |
60 |
| - let pool = EventLoopGroupConnectionPool( |
61 |
| - source: db, |
62 |
| - maxConnectionsPerEventLoop: maxConnectionsPerEventLoop, |
63 |
| - on: databases.eventLoopGroup |
64 |
| - ) |
65 |
| - return _FluentPostgresDriver(pool: pool) |
66 |
| - } |
67 |
| - |
68 |
| - |
69 |
| -} |
70 |
| - |
71 | 1 | enum FluentPostgresError: Error {
|
72 | 2 | case invalidURL(URL)
|
73 | 3 | }
|
|
0 commit comments