Skip to content

Commit

Permalink
Revert "fix npm pkg issues"
Browse files Browse the repository at this point in the history
This reverts commit 66752bd.
  • Loading branch information
f0rr0 committed Nov 19, 2024
1 parent 66752bd commit ecce7b7
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 19 deletions.
30 changes: 21 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,18 @@ This allows you to:
## How it Works

The proxy creates two servers:
1. A WebSocket server (port 443) that communicates with the database instance in the browser
2. A TCP server (port 5432) that accepts standard PostgreSQL client connections
1. A WebSocket server that communicates with the database instance in the browser
2. A TCP server that accepts standard PostgreSQL client connections

When a PostgreSQL client connects to the TCP server, the proxy:
1. Forwards the client's messages to the browser through WebSocket
2. Returns the browser's responses back to the client through TCP

### Examples

- [PGlite + Drizzle](https://github.com/f0rr0/pg-browser-proxy/tree/main/examples/pglite-drizzle)
- [PGlite + Prisma](https://github.com/f0rr0/pg-browser-proxy/tree/main/examples/pglite-prisma)

## Usage

### 1. Install the Packages
Expand All @@ -31,6 +36,16 @@ Using bunx:
bunx pg-browser-proxy
```

To use custom ports:
```sh
bunx pg-browser-proxy -t 5433 -w 8080
```

See all options:
```sh
bunx pg-browser-proxy -h
```

### 3. Connect Your Database Instance

```typescript
Expand All @@ -45,11 +60,13 @@ const db = await PGliteWorker.create(

// Connect to the proxy in development
if (process.env.NODE_ENV === "development" || process.env.NODE_ENV === "test") {
connectProxy((message) => db.execProtocolRaw(message));
connectProxy((message) => db.execProtocolRaw(message), {
wsPort: 443, // optional, defaults to 443
});
}
```

The key requirement is that your database must expose be able handle raw [Postgres wire protocol](https://www.postgresql.org/docs/current/protocol.html) messages.
The key requirement is that your database must be able to handle raw [Postgres wire protocol](https://www.postgresql.org/docs/current/protocol.html) messages.

### 4. Connect with PostgreSQL Tools

Expand Down Expand Up @@ -78,11 +95,6 @@ export default defineConfig({

- Only one browser connection is allowed at a time

### Examples

- [PGlite + Drizzle](git+https://github.com/f0rr0/pg-browser-proxy.git/tree/main/examples/pglite-drizzle)
- [PGlite + Prisma](git+https://github.com/f0rr0/pg-browser-proxy.git/tree/main/examples/pglite-prisma)

## Further Reading

- [pg-gateway](https://github.com/supabase-community/pg-gateway) - Built on top of this project
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
"prisma",
"studio"
],
"homepage": "git+https://github.com/f0rr0/pg-browser-proxy.git#readme",
"homepage": "https://github.com/f0rr0/pg-browser-proxy#readme",
"bugs": {
"url": "git+https://github.com/f0rr0/pg-browser-proxy.git/issues"
"url": "https://github.com/f0rr0/pg-browser-proxy/issues"
},
"repository": {
"type": "git",
"url": "git+https://github.com/f0rr0/pg-browser-proxy.git"
"url": "https://github.com/f0rr0/pg-browser-proxy"
},
"funding": {
"type": "github",
Expand Down
12 changes: 6 additions & 6 deletions packages/pg-browser-proxy/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@
"license": "MIT",
"repository": {
"type": "git",
"url": "git+git+https://github.com/f0rr0/pg-browser-proxy.git.git"
"url": "https://github.com/f0rr0/pg-browser-proxy"
},
"homepage": "git+https://github.com/f0rr0/pg-browser-proxy.git#readme",
"homepage": "https://github.com/f0rr0/pg-browser-proxy#readme",
"bugs": {
"url": "git+https://github.com/f0rr0/pg-browser-proxy.git/issues"
"url": "https://github.com/f0rr0/pg-browser-proxy/issues"
},
"funding": {
"type": "github",
Expand Down Expand Up @@ -73,11 +73,11 @@
"types": "./dist/browser/index.d.ts"
},
"./proxy": {
"import": "./dist/proxy/proxy.js",
"types": "./dist/proxy/proxy.d.ts"
"import": "./bin/src/proxy.js",
"types": "./bin/src/proxy.d.ts"
}
},
"bin": {
"pg-browser-proxy": "bin/bin.js"
"pg-proxy": "./bin/src/cli/bin.js"
}
}
2 changes: 1 addition & 1 deletion packages/pg-browser-proxy/src/cli/help.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const command: GluegunCommand = {
$ pg-proxy --tcp-port 5433 --ws-port 8080
${chalk.bold("Documentation:")}
${chalk.blue("git+https://github.com/f0rr0/pg-browser-proxy.git#readme")}
${chalk.blue("https://github.com/f0rr0/pg-browser-proxy#readme")}
${chalk.bold("Environment Variables:")}
${chalk.dim("DEBUG")} Enable debug logs (e.g., DEBUG=pg-proxy:*)
Expand Down

0 comments on commit ecce7b7

Please sign in to comment.