Package io.vertx.pgclient

## Interface PgConnection

- All Superinterfaces:
    `SqlClient`, `SqlConnection`

      public interface PgConnection
      extends SqlConnection

  A connection to Postgres.

  The connection object supports all the operations defined in the `SqlConnection` interface, it also provides additional support:

  - Notification
  - Request Cancellation
  Author:
    Julien Viet, Emad Alblueshi

- - ### Method Summary

    All Methods Static Methods Instance Methods Abstract Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `Future<Void>` | `cancelRequest()` | Send a request cancellation message to tell the server to cancel processing request in this connection.
    `static PgConnection` | `cast​(SqlConnection sqlConnection)` | Cast a `SqlConnection` to `PgConnection`.
    `PgConnection` | `closeHandler​(Handler<Void> handler)` | Set an handler called when the connection is closed.
    `static Future<PgConnection>` | `connect​(Vertx vertx)` | Like `connect(Vertx, PgConnectOptions)` with options build from the environment variables.
    `static Future<PgConnection>` | `connect​(Vertx vertx, PgConnectOptions options)` | Connects to the database and returns the connection if that succeeds.
    `static Future<PgConnection>` | `connect​(Vertx vertx, String connectionUri)` | Like `connect(Vertx, PgConnectOptions)` with options build from `connectionUri`.
    `PgConnection` | `exceptionHandler​(Handler<Throwable> handler)` | Set an handler called with connection errors.
    `PgConnection` | `noticeHandler​(Handler<PgNotice> handler)` | Set a handler called when the connection receives a notice from the server.
    `PgConnection` | `notificationHandler​(Handler<PgNotification> handler)` | Set a handler called when the connection receives notification on a channel.
    `int` | `processId()` |
    `int` | `secretKey()` |

    - ### Methods inherited from interface io.vertx.sqlclient.SqlClient

      `close, preparedQuery, preparedQuery, query`

    - ### Methods inherited from interface io.vertx.sqlclient.SqlConnection

      `begin, databaseMetadata, isSSL, prepare, prepare, transaction`

- - ### Method Detail

    - #### connect

          static Future<PgConnection> connect​(Vertx vertx,
                                              PgConnectOptions options)

      Connects to the database and returns the connection if that succeeds.

      The connection interracts directly with the database is not a proxy, so closing the connection will close the underlying connection to the database.
      Parameters:
        `vertx` - the vertx instance
        `options` - the connect options
      Returns:
        a future notified with the connection or the failure

    - #### connect

          static Future<PgConnection> connect​(Vertx vertx)

      Like `connect(Vertx, PgConnectOptions)` with options build from the environment variables.

    - #### connect

          static Future<PgConnection> connect​(Vertx vertx,
                                              String connectionUri)

      Like `connect(Vertx, PgConnectOptions)` with options build from `connectionUri`.

    - #### notificationHandler

          PgConnection notificationHandler​(Handler<PgNotification> handler)

      Set a handler called when the connection receives notification on a channel.

      The handler is called with the `PgNotification` and has access to the channel name and the notification payload.
      Parameters:
        `handler` - the handler
      Returns:
        the transaction instance

    - #### noticeHandler

          PgConnection noticeHandler​(Handler<PgNotice> handler)

      Set a handler called when the connection receives a notice from the server.
      Parameters:
        `handler` -
      Returns:

    - #### cancelRequest

          Future<Void> cancelRequest()

      Send a request cancellation message to tell the server to cancel processing request in this connection.
      Note: Use this with caution because the cancellation signal may or may not have any effect.
      Returns:
        a future notified if cancelling request is sent

    - #### processId

          int processId()

      Returns:
        The process ID of the target backend

    - #### secretKey

          int secretKey()

      Returns:
        The secret key for the target backend

    - #### exceptionHandler

          PgConnection exceptionHandler​(Handler<Throwable> handler)

      Set an handler called with connection errors.
      Specified by:
        `exceptionHandler` in interface `SqlConnection`
      Parameters:
        `handler` - the handler
      Returns:
        a reference to this, so the API can be used fluently

    - #### closeHandler

          PgConnection closeHandler​(Handler<Void> handler)

      Set an handler called when the connection is closed.
      Specified by:
        `closeHandler` in interface `SqlConnection`
      Parameters:
        `handler` - the handler
      Returns:
        a reference to this, so the API can be used fluently

    - #### cast

          static PgConnection cast​(SqlConnection sqlConnection)

      Cast a `SqlConnection` to `PgConnection`. This is mostly useful for Vert.x generated APIs like RxJava/Mutiny.
      Parameters:
        `sqlConnection` - the connection to cast
      Returns:
        a `instance`