1
1
extension DatabaseConfigurationFactory {
2
+ public static func postgres(
3
+ url urlString: String ,
4
+ maxConnectionsPerEventLoop: Int = 1 ,
5
+ encoder: PostgresDataEncoder = . init( ) ,
6
+ decoder: PostgresDataDecoder = . init( )
7
+ ) throws -> DatabaseConfigurationFactory {
8
+ guard let url = URL ( string: urlString) else {
9
+ throw FluentPostgresError . invalidURL ( urlString)
10
+ }
11
+ return try . postgres(
12
+ url: url,
13
+ maxConnectionsPerEventLoop: maxConnectionsPerEventLoop,
14
+ encoder: encoder,
15
+ decoder: decoder
16
+ )
17
+ }
18
+
2
19
public static func postgres(
3
20
url: URL ,
4
- maxConnectionsPerEventLoop: Int = 1
21
+ maxConnectionsPerEventLoop: Int = 1 ,
22
+ encoder: PostgresDataEncoder = . init( ) ,
23
+ decoder: PostgresDataDecoder = . init( )
5
24
) throws -> DatabaseConfigurationFactory {
6
25
guard let configuration = PostgresConfiguration ( url: url) else {
7
- throw FluentPostgresError . invalidURL ( url)
26
+ throw FluentPostgresError . invalidURL ( url. absoluteString )
8
27
}
9
28
return . postgres(
10
29
configuration: configuration,
@@ -19,7 +38,9 @@ extension DatabaseConfigurationFactory {
19
38
password: String ,
20
39
database: String ? = nil ,
21
40
tlsConfiguration: TLSConfiguration ? = nil ,
22
- maxConnectionsPerEventLoop: Int = 1
41
+ maxConnectionsPerEventLoop: Int = 1 ,
42
+ encoder: PostgresDataEncoder = . init( ) ,
43
+ decoder: PostgresDataDecoder = . init( )
23
44
) -> DatabaseConfigurationFactory {
24
45
return . postgres(
25
46
configuration: . init(
@@ -36,13 +57,17 @@ extension DatabaseConfigurationFactory {
36
57
37
58
public static func postgres(
38
59
configuration: PostgresConfiguration ,
39
- maxConnectionsPerEventLoop: Int = 1
60
+ maxConnectionsPerEventLoop: Int = 1 ,
61
+ encoder: PostgresDataEncoder = . init( ) ,
62
+ decoder: PostgresDataDecoder = . init( )
40
63
) -> DatabaseConfigurationFactory {
41
64
return DatabaseConfigurationFactory {
42
65
FluentPostgresConfiguration (
43
66
middleware: [ ] ,
44
67
configuration: configuration,
45
- maxConnectionsPerEventLoop: maxConnectionsPerEventLoop
68
+ maxConnectionsPerEventLoop: maxConnectionsPerEventLoop,
69
+ encoder: encoder,
70
+ decoder: decoder
46
71
)
47
72
}
48
73
}
@@ -52,6 +77,8 @@ struct FluentPostgresConfiguration: DatabaseConfiguration {
52
77
var middleware : [ AnyModelMiddleware ]
53
78
let configuration : PostgresConfiguration
54
79
let maxConnectionsPerEventLoop : Int
80
+ let encoder : PostgresDataEncoder
81
+ let decoder : PostgresDataDecoder
55
82
56
83
func makeDriver( for databases: Databases ) -> DatabaseDriver {
57
84
let db = PostgresConnectionSource (
@@ -62,6 +89,10 @@ struct FluentPostgresConfiguration: DatabaseConfiguration {
62
89
maxConnectionsPerEventLoop: maxConnectionsPerEventLoop,
63
90
on: databases. eventLoopGroup
64
91
)
65
- return _FluentPostgresDriver ( pool: pool)
92
+ return _FluentPostgresDriver (
93
+ pool: pool,
94
+ encoder: encoder,
95
+ decoder: decoder
96
+ )
66
97
}
67
98
}
0 commit comments