@@ -8,11 +8,11 @@ import _ConnectionPoolModule
8
8
/// A Postgres client that is backed by an underlying connection pool. Use ``Configuration`` to change the client's
9
9
/// behavior.
10
10
///
11
- /// > Important :
11
+ /// > Warning :
12
12
/// The client can only lease connections if the user is running the client's ``run()`` method in a long running task:
13
13
///
14
14
/// ```swift
15
- /// let client = PostgresClient(configuration: configuration, logger: logger )
15
+ /// let client = PostgresClient(configuration: configuration)
16
16
/// await withTaskGroup(of: Void.self) {
17
17
/// taskGroup.addTask {
18
18
/// client.run() // !important
@@ -32,7 +32,6 @@ import _ConnectionPoolModule
32
32
/// }
33
33
/// ```
34
34
@available ( macOS 13 . 0 , iOS 16 . 0 , tvOS 16 . 0 , watchOS 9 . 0 , * )
35
- @_spi ( ConnectionPool)
36
35
public final class PostgresClient : Sendable , ServiceLifecycle . Service {
37
36
public struct Configuration : Sendable {
38
37
public struct TLS : Sendable {
@@ -246,8 +245,22 @@ public final class PostgresClient: Sendable, ServiceLifecycle.Service {
246
245
let factory : ConnectionFactory
247
246
let runningAtomic = ManagedAtomic ( false )
248
247
let backgroundLogger : Logger
249
-
248
+
249
+ /// Creates a new ``PostgresClient``, that does not log any background information.
250
+ /// Don't forget to run ``run()`` the client in a long running task.
251
+ ///
252
+ /// - Parameters:
253
+ /// - configuration: The client's configuration. See ``Configuration`` for details.
254
+ /// - eventLoopGroup: The underlying NIO `EventLoopGroup`. Defaults to ``defaultEventLoopGroup``.
255
+ public convenience init (
256
+ configuration: Configuration ,
257
+ eventLoopGroup: any EventLoopGroup = PostgresClient . defaultEventLoopGroup
258
+ ) {
259
+ self . init ( configuration: configuration, eventLoopGroup: eventLoopGroup, backgroundLogger: Self . loggingDisabled)
260
+ }
261
+
250
262
/// Creates a new ``PostgresClient``. Don't forget to run ``run()`` the client in a long running task.
263
+ ///
251
264
/// - Parameters:
252
265
/// - configuration: The client's configuration. See ``Configuration`` for details.
253
266
/// - eventLoopGroup: The underlying NIO `EventLoopGroup`. Defaults to ``defaultEventLoopGroup``.
@@ -302,10 +315,11 @@ public final class PostgresClient: Sendable, ServiceLifecycle.Service {
302
315
@discardableResult
303
316
public func query(
304
317
_ query: PostgresQuery ,
305
- logger: Logger ,
318
+ logger: Logger ? = nil ,
306
319
file: String = #fileID,
307
320
line: Int = #line
308
321
) async throws -> PostgresRowSequence {
322
+ let logger = logger ?? Self . loggingDisabled
309
323
do {
310
324
guard query. binds. count <= Int ( UInt16 . max) else {
311
325
throw PSQLError ( code: . tooManyParameters, query: query, file: file, line: line)
@@ -345,11 +359,12 @@ public final class PostgresClient: Sendable, ServiceLifecycle.Service {
345
359
/// Execute a prepared statement, taking care of the preparation when necessary
346
360
public func execute< Statement: PostgresPreparedStatement , Row> (
347
361
_ preparedStatement: Statement ,
348
- logger: Logger ,
362
+ logger: Logger ? = nil ,
349
363
file: String = #fileID,
350
364
line: Int = #line
351
365
) async throws -> AsyncThrowingMapSequence < PostgresRowSequence , Row > where Row == Statement . Row {
352
366
let bindings = try preparedStatement. makeBindings ( )
367
+ let logger = logger ?? Self . loggingDisabled
353
368
354
369
do {
355
370
let connection = try await self . leaseConnection ( )
@@ -412,6 +427,8 @@ public final class PostgresClient: Sendable, ServiceLifecycle.Service {
412
427
public static var defaultEventLoopGroup : EventLoopGroup {
413
428
PostgresConnection . defaultEventLoopGroup
414
429
}
430
+
431
+ static let loggingDisabled = Logger ( label: " Postgres-do-not-log " , factory: { _ in SwiftLogNoOpLogHandler ( ) } )
415
432
}
416
433
417
434
@available ( macOS 13 . 0 , iOS 16 . 0 , tvOS 16 . 0 , watchOS 9 . 0 , * )
@@ -444,7 +461,6 @@ extension ConnectionPoolConfiguration {
444
461
}
445
462
}
446
463
447
- @_spi ( ConnectionPool)
448
464
extension PostgresConnection : PooledConnection {
449
465
public func close( ) {
450
466
self . channel. close ( mode: . all, promise: nil )
0 commit comments