PostgresConnectionSource.swift 754 B

12345678910111213141516171819202122232425
  1. import Hummingbird
  2. import Logging
  3. import PostgresNIO
  4. extension PostgresConnection: HBConnection {
  5. public func close(on eventLoop: EventLoop) -> EventLoopFuture<Void> {
  6. return close().hop(to: eventLoop)
  7. }
  8. }
  9. struct PostgresConnectionSource: HBConnectionSource {
  10. typealias Connection = PostgresConnection
  11. let configuration: PostgresConnection.Configuration
  12. init(configuration: PostgresConnection.Configuration) {
  13. self.configuration = configuration
  14. }
  15. func makeConnection(on eventLoop: EventLoop, logger: Logger) -> EventLoopFuture<Connection> {
  16. let connection = PostgresConnection.connect(on: eventLoop, configuration: self.configuration, id: 0, logger: logger)
  17. return connection
  18. }
  19. }