Class
PostgresConnection
A Postgres connection. Use it to run queries against a Postgres server.
final class PostgresConnection
Overview
Thread safety is achieved by dispatching all access to shared state onto the underlying EventLoop.
Topics
Structures
PostgresConnection.ConfigurationA configuration object for a connection.
Instance Properties
closeFutureeventLoopThe underlyingEventLoopof both the connection and its channel.idThe connection’s identifier. The identifier is passed to the connection factory method and must stay attached to the connection at all times. It must not change during the connection’s lifetime.isClosedloggerA logger to use for background events.
Instance Methods
addListener(channel:handler:)Add a handler for NotificationResponse messages on a certain channel. This is used in conjunction with PostgreSQL’sLISTEN/NOTIFYsupport: to listen on a channel, you add a listener using this method to handle the NotificationResponse messages, then issue aLISTENquery to instruct PostgreSQL to begin sending NotificationResponse messages.authenticate(username:database:password:logger:)closeGracefully()Closes the connection to the server, after all queries that have been created on this connection have been run.copyFrom(table:columns:format:logger:file:line:writeData:)Copy data into a table using aCOPY <table name> FROM STDINquery.execute(_:logger:file:line:)Execute a prepared statement, taking care of the preparation when necessary.listen(_:)Start listening for a channel.listen(on:consume:)Listen to a channel and run closure withPostgresNotificationSequence.query(_:logger:file:line:)Run a query on the Postgres server the connection is connected to.query(_:logger:file:line:_:)Run a query on the Postgres server the connection is connected to and iterate the rows in a callback.withTransaction(logger:file:line:isolation:_:)Puts the connection into an open transaction state, for the providedclosure’s lifetime.
Type Aliases
PostgresConnection.IDA Postgres connection ID.
Type Properties
defaultEventLoopGroupReturns the defaultEventLoopGroupsingleton, automatically selecting the best for the platform.
Type Methods
connect(on:configuration:id:logger:)Creates a new connection to a Postgres server.connect(to:tlsConfiguration:serverHostname:logger:on:)
Default Implementations
Relationships
Conforms To
PostgresDatabaseSwift.CopyableSwift.EscapableSwift.SendableSwift.SendableMetatype_ConnectionPoolModule.PooledConnection
See Also
Essentials
PostgresClientA Postgres client that is backed by an underlying connection pool. UsePostgresClient.Configurationto change the client’s behavior.PostgresClient.Configuration- Running QueriesInteract with the PostgreSQL database by running Queries.