1
- extension DatabaseDriverFactory {
1
+ extension DatabaseConfigurationFactory {
2
2
public static func postgres(
3
3
url: URL ,
4
4
maxConnectionsPerEventLoop: Int = 1
5
- ) throws -> DatabaseDriverFactory {
5
+ ) throws -> DatabaseConfigurationFactory {
6
6
guard let configuration = PostgresConfiguration ( url: url) else {
7
7
throw FluentPostgresError . invalidURL ( url)
8
8
}
@@ -20,7 +20,7 @@ extension DatabaseDriverFactory {
20
20
database: String ? = nil ,
21
21
tlsConfiguration: TLSConfiguration ? = nil ,
22
22
maxConnectionsPerEventLoop: Int = 1
23
- ) -> DatabaseDriverFactory {
23
+ ) -> DatabaseConfigurationFactory {
24
24
return . postgres(
25
25
configuration: . init(
26
26
hostname: hostname,
@@ -37,21 +37,37 @@ extension DatabaseDriverFactory {
37
37
public static func postgres(
38
38
configuration: PostgresConfiguration ,
39
39
maxConnectionsPerEventLoop: Int = 1
40
- ) -> DatabaseDriverFactory {
41
- return DatabaseDriverFactory { databases in
42
- let db = PostgresConnectionSource (
43
- configuration: configuration
40
+ ) -> DatabaseConfigurationFactory {
41
+ return DatabaseConfigurationFactory {
42
+ FluentPostgresConfiguration (
43
+ middleware: [ ] ,
44
+ configuration: configuration,
45
+ maxConnectionsPerEventLoop: maxConnectionsPerEventLoop
44
46
)
45
- let pool = EventLoopGroupConnectionPool (
46
- source: db,
47
- maxConnectionsPerEventLoop: maxConnectionsPerEventLoop,
48
- on: databases. eventLoopGroup
49
- )
50
- return _FluentPostgresDriver ( pool: pool)
51
47
}
52
48
}
53
49
}
54
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
+
55
71
enum FluentPostgresError : Error {
56
72
case invalidURL( URL )
57
73
}
0 commit comments