@@ -6,6 +6,157 @@ import NIOCore
6
6
import PostgresKit
7
7
import PostgresNIO
8
8
9
+ extension DatabaseConfigurationFactory {
10
+ /// Create a PostgreSQL database configuration from a URL string.
11
+ ///
12
+ /// See ``PostgresKit/SQLPostgresConfiguration/init(url:)`` for the allowed URL format.
13
+ ///
14
+ /// - Parameters:
15
+ /// - urlString: The URL describing the connection, as a string.
16
+ /// - maxConnectionsPerEventLoop: Maximum number of connections to open per event loop.
17
+ /// - connectionPoolTimeout: Maximum time to wait for a connection to become available per request.
18
+ /// - encodingContext: Encoding context to use for serializing data.
19
+ /// - decodingContext: Decoding context to use for deserializing data.
20
+ /// - sqlLogLevel: Level at which to log SQL queries.
21
+ public static func postgres(
22
+ url urlString: String ,
23
+ maxConnectionsPerEventLoop: Int = 1 ,
24
+ connectionPoolTimeout: TimeAmount = . seconds( 10 ) ,
25
+ encodingContext: PostgresEncodingContext < some PostgresJSONEncoder > = . default,
26
+ decodingContext: PostgresDecodingContext < some PostgresJSONDecoder > = . default,
27
+ sqlLogLevel: Logger . Level = . debug
28
+ ) throws -> Self {
29
+ . postgres(
30
+ configuration: try . init( url: urlString) ,
31
+ maxConnectionsPerEventLoop: maxConnectionsPerEventLoop,
32
+ connectionPoolTimeout: connectionPoolTimeout,
33
+ pruneInterval: nil ,
34
+ encodingContext: encodingContext,
35
+ decodingContext: decodingContext,
36
+ sqlLogLevel: sqlLogLevel
37
+ )
38
+ }
39
+
40
+ /// Create a PostgreSQL database configuration from a URL.
41
+ ///
42
+ /// See ``PostgresKit/SQLPostgresConfiguration/init(url:)`` for the allowed URL format.
43
+ ///
44
+ /// - Parameters:
45
+ /// - url: The URL describing the connection.
46
+ /// - maxConnectionsPerEventLoop: Maximum number of connections to open per event loop.
47
+ /// - connectionPoolTimeout: Maximum time to wait for a connection to become available per request.
48
+ /// - encodingContext: Encoding context to use for serializing data.
49
+ /// - decodingContext: Decoding context to use for deserializing data.
50
+ /// - sqlLogLevel: Level at which to log SQL queries.
51
+ public static func postgres(
52
+ url: URL ,
53
+ maxConnectionsPerEventLoop: Int = 1 ,
54
+ connectionPoolTimeout: TimeAmount = . seconds( 10 ) ,
55
+ encodingContext: PostgresEncodingContext < some PostgresJSONEncoder > = . default,
56
+ decodingContext: PostgresDecodingContext < some PostgresJSONDecoder > = . default,
57
+ sqlLogLevel: Logger . Level = . debug
58
+ ) throws -> Self {
59
+ . postgres(
60
+ configuration: try . init( url: url) ,
61
+ maxConnectionsPerEventLoop: maxConnectionsPerEventLoop,
62
+ connectionPoolTimeout: connectionPoolTimeout,
63
+ pruneInterval: nil ,
64
+ encodingContext: encodingContext,
65
+ decodingContext: decodingContext,
66
+ sqlLogLevel: sqlLogLevel
67
+ )
68
+ }
69
+
70
+ /// Create a PostgreSQL database configuration from lower-level configuration.
71
+ ///
72
+ /// - Parameters:
73
+ /// - configuration: A ``PostgresKit/SQLPostgresConfiguration`` describing the connection.
74
+ /// - maxConnectionsPerEventLoop: Maximum number of connections to open per event loop.
75
+ /// - connectionPoolTimeout: Maximum time to wait for a connection to become available per request.
76
+ /// - encodingContext: Encoding context to use for serializing data.
77
+ /// - decodingContext: Decoding context to use for deserializing data.
78
+ /// - sqlLogLevel: Level at which to log SQL queries.
79
+ public static func postgres(
80
+ configuration: SQLPostgresConfiguration ,
81
+ maxConnectionsPerEventLoop: Int = 1 ,
82
+ connectionPoolTimeout: TimeAmount = . seconds( 10 ) ,
83
+ encodingContext: PostgresEncodingContext < some PostgresJSONEncoder > ,
84
+ decodingContext: PostgresDecodingContext < some PostgresJSONDecoder > ,
85
+ sqlLogLevel: Logger . Level = . debug
86
+ ) -> Self {
87
+ . postgres(
88
+ configuration: configuration,
89
+ maxConnectionsPerEventLoop: maxConnectionsPerEventLoop,
90
+ connectionPoolTimeout: connectionPoolTimeout,
91
+ pruneInterval: nil ,
92
+ encodingContext: encodingContext,
93
+ decodingContext: decodingContext,
94
+ sqlLogLevel: sqlLogLevel
95
+ )
96
+ }
97
+ }
98
+
99
+ extension DatabaseConfigurationFactory {
100
+ /// ``postgres(configuration:maxConnectionsPerEventLoop:connectionPoolTimeout:encodingContext:decodingContext:sqlLogLevel:)``
101
+ /// with the `decodingContext` defaulted.
102
+ public static func postgres(
103
+ configuration: SQLPostgresConfiguration ,
104
+ maxConnectionsPerEventLoop: Int = 1 ,
105
+ connectionPoolTimeout: TimeAmount = . seconds( 10 ) ,
106
+ encodingContext: PostgresEncodingContext < some PostgresJSONEncoder > ,
107
+ sqlLogLevel: Logger . Level = . debug
108
+ ) -> Self {
109
+ . postgres(
110
+ configuration: configuration,
111
+ maxConnectionsPerEventLoop: maxConnectionsPerEventLoop,
112
+ connectionPoolTimeout: connectionPoolTimeout,
113
+ pruneInterval: nil ,
114
+ encodingContext: encodingContext,
115
+ decodingContext: . default,
116
+ sqlLogLevel: sqlLogLevel
117
+ )
118
+ }
119
+
120
+ /// ``postgres(configuration:maxConnectionsPerEventLoop:connectionPoolTimeout:encodingContext:decodingContext:sqlLogLevel:)``
121
+ /// with the `encodingContext` defaulted.
122
+ public static func postgres(
123
+ configuration: SQLPostgresConfiguration ,
124
+ maxConnectionsPerEventLoop: Int = 1 ,
125
+ connectionPoolTimeout: TimeAmount = . seconds( 10 ) ,
126
+ decodingContext: PostgresDecodingContext < some PostgresJSONDecoder > ,
127
+ sqlLogLevel: Logger . Level = . debug
128
+ ) -> Self {
129
+ . postgres(
130
+ configuration: configuration,
131
+ maxConnectionsPerEventLoop: maxConnectionsPerEventLoop,
132
+ connectionPoolTimeout: connectionPoolTimeout,
133
+ pruneInterval: nil ,
134
+ encodingContext: . default,
135
+ decodingContext: decodingContext,
136
+ sqlLogLevel: sqlLogLevel
137
+ )
138
+ }
139
+
140
+ /// ``postgres(configuration:maxConnectionsPerEventLoop:connectionPoolTimeout:encodingContext:decodingContext:sqlLogLevel:)``
141
+ /// with both `encodingContext` and `decodingContext` defaulted.
142
+ public static func postgres(
143
+ configuration: SQLPostgresConfiguration ,
144
+ maxConnectionsPerEventLoop: Int = 1 ,
145
+ connectionPoolTimeout: TimeAmount = . seconds( 10 ) ,
146
+ sqlLogLevel: Logger . Level = . debug
147
+ ) -> Self {
148
+ . postgres(
149
+ configuration: configuration,
150
+ maxConnectionsPerEventLoop: maxConnectionsPerEventLoop,
151
+ connectionPoolTimeout: connectionPoolTimeout,
152
+ pruneInterval: nil ,
153
+ encodingContext: . default,
154
+ decodingContext: . default,
155
+ sqlLogLevel: sqlLogLevel
156
+ )
157
+ }
158
+ }
159
+
9
160
extension DatabaseConfigurationFactory {
10
161
/// Create a PostgreSQL database configuration from a URL string.
11
162
///
@@ -26,12 +177,12 @@ extension DatabaseConfigurationFactory {
26
177
url urlString: String ,
27
178
maxConnectionsPerEventLoop: Int = 1 ,
28
179
connectionPoolTimeout: TimeAmount = . seconds( 10 ) ,
29
- pruneInterval: TimeAmount ? = nil ,
180
+ pruneInterval: TimeAmount ? ,
30
181
maxIdleTimeBeforePruning: TimeAmount = . seconds( 120 ) ,
31
182
encodingContext: PostgresEncodingContext < some PostgresJSONEncoder > = . default,
32
183
decodingContext: PostgresDecodingContext < some PostgresJSONDecoder > = . default,
33
184
sqlLogLevel: Logger . Level = . debug
34
- ) throws -> DatabaseConfigurationFactory {
185
+ ) throws -> Self {
35
186
. postgres(
36
187
configuration: try . init( url: urlString) ,
37
188
maxConnectionsPerEventLoop: maxConnectionsPerEventLoop,
@@ -63,12 +214,12 @@ extension DatabaseConfigurationFactory {
63
214
url: URL ,
64
215
maxConnectionsPerEventLoop: Int = 1 ,
65
216
connectionPoolTimeout: TimeAmount = . seconds( 10 ) ,
66
- pruneInterval: TimeAmount ? = nil ,
217
+ pruneInterval: TimeAmount ? ,
67
218
maxIdleTimeBeforePruning: TimeAmount = . seconds( 120 ) ,
68
219
encodingContext: PostgresEncodingContext < some PostgresJSONEncoder > = . default,
69
220
decodingContext: PostgresDecodingContext < some PostgresJSONDecoder > = . default,
70
221
sqlLogLevel: Logger . Level = . debug
71
- ) throws -> DatabaseConfigurationFactory {
222
+ ) throws -> Self {
72
223
. postgres(
73
224
configuration: try . init( url: url) ,
74
225
maxConnectionsPerEventLoop: maxConnectionsPerEventLoop,
@@ -98,12 +249,12 @@ extension DatabaseConfigurationFactory {
98
249
configuration: SQLPostgresConfiguration ,
99
250
maxConnectionsPerEventLoop: Int = 1 ,
100
251
connectionPoolTimeout: TimeAmount = . seconds( 10 ) ,
101
- pruneInterval: TimeAmount ? = nil ,
252
+ pruneInterval: TimeAmount ? ,
102
253
maxIdleTimeBeforePruning: TimeAmount = . seconds( 120 ) ,
103
254
encodingContext: PostgresEncodingContext < some PostgresJSONEncoder > ,
104
255
decodingContext: PostgresDecodingContext < some PostgresJSONDecoder > ,
105
256
sqlLogLevel: Logger . Level = . debug
106
- ) -> DatabaseConfigurationFactory {
257
+ ) -> Self {
107
258
. init {
108
259
FluentPostgresConfiguration (
109
260
configuration: configuration,
@@ -138,11 +289,11 @@ extension DatabaseConfigurationFactory {
138
289
configuration: SQLPostgresConfiguration ,
139
290
maxConnectionsPerEventLoop: Int = 1 ,
140
291
connectionPoolTimeout: TimeAmount = . seconds( 10 ) ,
141
- pruneInterval: TimeAmount ? = nil ,
292
+ pruneInterval: TimeAmount ? ,
142
293
maxIdleTimeBeforePruning: TimeAmount = . seconds( 120 ) ,
143
294
encodingContext: PostgresEncodingContext < some PostgresJSONEncoder > ,
144
295
sqlLogLevel: Logger . Level = . debug
145
- ) -> DatabaseConfigurationFactory {
296
+ ) -> Self {
146
297
. postgres(
147
298
configuration: configuration,
148
299
maxConnectionsPerEventLoop: maxConnectionsPerEventLoop,
@@ -161,11 +312,11 @@ extension DatabaseConfigurationFactory {
161
312
configuration: SQLPostgresConfiguration ,
162
313
maxConnectionsPerEventLoop: Int = 1 ,
163
314
connectionPoolTimeout: TimeAmount = . seconds( 10 ) ,
164
- pruneInterval: TimeAmount ? = nil ,
315
+ pruneInterval: TimeAmount ? ,
165
316
maxIdleTimeBeforePruning: TimeAmount = . seconds( 120 ) ,
166
317
decodingContext: PostgresDecodingContext < some PostgresJSONDecoder > ,
167
318
sqlLogLevel: Logger . Level = . debug
168
- ) -> DatabaseConfigurationFactory {
319
+ ) -> Self {
169
320
. postgres(
170
321
configuration: configuration,
171
322
maxConnectionsPerEventLoop: maxConnectionsPerEventLoop,
@@ -184,10 +335,10 @@ extension DatabaseConfigurationFactory {
184
335
configuration: SQLPostgresConfiguration ,
185
336
maxConnectionsPerEventLoop: Int = 1 ,
186
337
connectionPoolTimeout: TimeAmount = . seconds( 10 ) ,
187
- pruneInterval: TimeAmount ? = nil ,
338
+ pruneInterval: TimeAmount ? ,
188
339
maxIdleTimeBeforePruning: TimeAmount = . seconds( 120 ) ,
189
340
sqlLogLevel: Logger . Level = . debug
190
- ) -> DatabaseConfigurationFactory {
341
+ ) -> Self {
191
342
. postgres(
192
343
configuration: configuration,
193
344
maxConnectionsPerEventLoop: maxConnectionsPerEventLoop,
0 commit comments