https://github.com/estebgonza/ts-pg-interceptor
A TCP proxy server with the ability to intercept and manipulate PostgreSQL requests.
https://github.com/estebgonza/ts-pg-interceptor
postgres postgresql postgresql-database proxy proxy-server queries sql tcp-proxy tcp-server typescript
Last synced: 7 months ago
JSON representation
A TCP proxy server with the ability to intercept and manipulate PostgreSQL requests.
- Host: GitHub
- URL: https://github.com/estebgonza/ts-pg-interceptor
- Owner: estebgonza
- Created: 2023-02-14T23:12:14.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2023-12-15T05:22:58.000Z (over 2 years ago)
- Last Synced: 2025-08-10T12:38:44.878Z (8 months ago)
- Topics: postgres, postgresql, postgresql-database, proxy, proxy-server, queries, sql, tcp-proxy, tcp-server, typescript
- Language: TypeScript
- Homepage:
- Size: 22.4 MB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# PostgreSQL Request Interceptor

A TCP proxy server with the ability to intercept and manipulate PostgreSQL requests. This package provides an event-driven approach to data handling, making it easy to listen for and modify incoming requests.
## Create an interceptor instance
----------------
```ts
// Create a new PostgresQueryInterceptor instance with the desired options
const interceptor = new PostgresQueryInterceptor({
// Interceptor server options
listenPort: 6432,
// Target Postgres connection options
targetHost: 'localhost',
targetPort: 5432
});
// Start the interceptor and begin intercepting incoming requests
interceptor.start()
```
## Modify incoming requests
----------------
```ts
interceptor.onQuery = (query: Buffer, socket: net.Socket) => {
const modifiedQuery = query
// Your logic to modify the query as desired
// Use the socket as needed to manage the connection
// The returned query will be sent to the target Postgres server
return modifiedQuery
}
```
## Modify outgoing results
----------------
```ts
interceptor.onResult = (result: Buffer, socket: net.Socket) => {
const modifiedResult = result
// Your logic to modify the result as desired
// Use the socket as needed to manage the connection
// The returned result will be sent to the client
return modifiedResult
}
```
## Stop the interceptor
----------------
```ts
interceptor.stop()
```