Skip to content

Commit

Permalink
docs(readme): detach method
Browse files Browse the repository at this point in the history
  • Loading branch information
gregnr committed Jul 26, 2024
1 parent d705861 commit 8ba5238
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ const connection = new PostgresConnection(socket, {

This hook is called after the TLS upgrade has completed. It passes a [`state`](#state) argument which holds connection information gathered so far like `tlsInfo`. The callback can be either synchronous or asynchronous.

This will be called before the startup message is received from the frontend (if TLS is being used) so is a good place to establish [proxy connections](#reverse-proxy-using-sni) if desired.
This will be called before the startup message is received from the frontend (if TLS is being used) so is a good place to establish [proxy connections](#reverse-proxy-using-sni) if desired. Note that a [`detach()`](#detach) method is also available if you wish to detach from the `PostgresConnection` after the proxy has been established.

```typescript
const tls: TlsOptions = {
Expand Down Expand Up @@ -242,6 +242,17 @@ console.log(connection.state);

It is also passed as an argument to most hooks for convenience.

## `detach()`

A `detach()` method exists on the `PostgresConnection` to allow you to completely detach the socket from the `PostgresConnection` and handle all future data processing yourself. This is useful when [reverse proxying](#reverse-proxy-using-sni) to prevent the `PostgresConnection` from continuing to process each message after the proxy connection is established.

Calling `detach()` will return the current `Socket` which may be different than the original socket if a TLS upgrade occurred (ie. a `TLSSocket`). The `PostgresConnection` will remove all event listeners from the socket and no further processing will take place.

```typescript
const connection = new PostgresConnection(socket);
const socket = connection.detach();
```

## Examples

### PGlite
Expand Down

0 comments on commit 8ba5238

Please sign in to comment.