11extension 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+ 219 public static func postgres(
320 url: URL ,
4- maxConnectionsPerEventLoop: Int = 1
21+ maxConnectionsPerEventLoop: Int = 1 ,
22+ encoder: PostgresDataEncoder = . init( ) ,
23+ decoder: PostgresDataDecoder = . init( )
524 ) throws -> DatabaseConfigurationFactory {
625 guard let configuration = PostgresConfiguration ( url: url) else {
7- throw FluentPostgresError . invalidURL ( url)
26+ throw FluentPostgresError . invalidURL ( url. absoluteString )
827 }
928 return . postgres(
1029 configuration: configuration,
@@ -19,7 +38,9 @@ extension DatabaseConfigurationFactory {
1938 password: String ,
2039 database: String ? = nil ,
2140 tlsConfiguration: TLSConfiguration ? = nil ,
22- maxConnectionsPerEventLoop: Int = 1
41+ maxConnectionsPerEventLoop: Int = 1 ,
42+ encoder: PostgresDataEncoder = . init( ) ,
43+ decoder: PostgresDataDecoder = . init( )
2344 ) -> DatabaseConfigurationFactory {
2445 return . postgres(
2546 configuration: . init(
@@ -36,13 +57,17 @@ extension DatabaseConfigurationFactory {
3657
3758 public static func postgres(
3859 configuration: PostgresConfiguration ,
39- maxConnectionsPerEventLoop: Int = 1
60+ maxConnectionsPerEventLoop: Int = 1 ,
61+ encoder: PostgresDataEncoder = . init( ) ,
62+ decoder: PostgresDataDecoder = . init( )
4063 ) -> DatabaseConfigurationFactory {
4164 return DatabaseConfigurationFactory {
4265 FluentPostgresConfiguration (
4366 middleware: [ ] ,
4467 configuration: configuration,
45- maxConnectionsPerEventLoop: maxConnectionsPerEventLoop
68+ maxConnectionsPerEventLoop: maxConnectionsPerEventLoop,
69+ encoder: encoder,
70+ decoder: decoder
4671 )
4772 }
4873 }
@@ -52,6 +77,8 @@ struct FluentPostgresConfiguration: DatabaseConfiguration {
5277 var middleware : [ AnyModelMiddleware ]
5378 let configuration : PostgresConfiguration
5479 let maxConnectionsPerEventLoop : Int
80+ let encoder : PostgresDataEncoder
81+ let decoder : PostgresDataDecoder
5582
5683 func makeDriver( for databases: Databases ) -> DatabaseDriver {
5784 let db = PostgresConnectionSource (
@@ -62,6 +89,10 @@ struct FluentPostgresConfiguration: DatabaseConfiguration {
6289 maxConnectionsPerEventLoop: maxConnectionsPerEventLoop,
6390 on: databases. eventLoopGroup
6491 )
65- return _FluentPostgresDriver ( pool: pool)
92+ return _FluentPostgresDriver (
93+ pool: pool,
94+ encoder: encoder,
95+ decoder: decoder
96+ )
6697 }
6798}
0 commit comments