|
| 1 | +extension EventLoopGroupConnectionPool where Source == PostgresConnectionSource { |
| 2 | + public func database(logger: Logger) -> PostgresDatabase { |
| 3 | + _EventLoopGroupConnectionPoolPostgresDatabase(pool: self, logger: logger) |
| 4 | + } |
| 5 | +} |
| 6 | + |
| 7 | +private struct _EventLoopGroupConnectionPoolPostgresDatabase { |
| 8 | + let pool: EventLoopGroupConnectionPool<PostgresConnectionSource> |
| 9 | + let logger: Logger |
| 10 | +} |
| 11 | + |
| 12 | +extension _EventLoopGroupConnectionPoolPostgresDatabase: PostgresDatabase { |
| 13 | + var eventLoop: EventLoop { self.pool.eventLoopGroup.next() } |
| 14 | + |
| 15 | + func send(_ request: PostgresRequest, logger: Logger) -> EventLoopFuture<Void> { |
| 16 | + self.pool.withConnection(logger: logger) { |
| 17 | + $0.send(request, logger: logger) |
| 18 | + } |
| 19 | + } |
| 20 | + |
| 21 | + func withConnection<T>(_ closure: @escaping (PostgresConnection) -> EventLoopFuture<T>) -> EventLoopFuture<T> { |
| 22 | + self.pool.withConnection(logger: self.logger, closure) |
| 23 | + } |
| 24 | +} |
| 25 | + |
1 | 26 | extension EventLoopConnectionPool where Source == PostgresConnectionSource {
|
2 | 27 | public func database(logger: Logger) -> PostgresDatabase {
|
3 |
| - _ConnectionPoolPostgresDatabase(pool: self, logger: logger) |
| 28 | + _EventLoopConnectionPoolPostgresDatabase(pool: self, logger: logger) |
4 | 29 | }
|
5 | 30 | }
|
6 | 31 |
|
7 |
| -private struct _ConnectionPoolPostgresDatabase { |
| 32 | +private struct _EventLoopConnectionPoolPostgresDatabase { |
8 | 33 | let pool: EventLoopConnectionPool<PostgresConnectionSource>
|
9 | 34 | let logger: Logger
|
10 | 35 | }
|
11 | 36 |
|
12 |
| -extension _ConnectionPoolPostgresDatabase: PostgresDatabase { |
| 37 | +extension _EventLoopConnectionPoolPostgresDatabase: PostgresDatabase { |
13 | 38 | var eventLoop: EventLoop { self.pool.eventLoop }
|
14 | 39 |
|
15 | 40 | func send(_ request: PostgresRequest, logger: Logger) -> EventLoopFuture<Void> {
|
|
0 commit comments