Skip to content

Commit

Permalink
fix npm pkg issues
Browse files Browse the repository at this point in the history
  • Loading branch information
f0rr0 committed Nov 19, 2024
1 parent ecce7b7 commit 7ec4a6b
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 13 deletions.
13 changes: 10 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,19 @@
A WebSocket-TCP proxy that enables PostgreSQL clients to connect to a Postgres database running in the browser. Designed to work with [PGlite](https://pglite.dev/), a lightweight embeddable Postgres that runs in WebAssembly.

This allows you to:

- Use standard PostgreSQL clients (psql, pgAdmin, [Drizzle Studio](https://orm.drizzle.team/drizzle-studio/overview), etc.) to connect to a browser-based database
- Use tools like `pg_dump` to backup your database

## How it Works

The proxy creates two servers:

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

Expand All @@ -32,16 +35,19 @@ bun add pg-browser-proxy
### 2. Start the Proxy

Using bunx:

```sh
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
```
Expand All @@ -55,7 +61,7 @@ import { PGliteWorker } from "@electric-sql/pglite/worker";
const db = await PGliteWorker.create(
new Worker(new URL("./worker", import.meta.url), {
type: "module",
})
}),
);

// Connect to the proxy in development
Expand All @@ -81,13 +87,14 @@ pg_dump -h localhost -p 5432 -U postgres > backup.sql
```

For tools like Drizzle Studio, configure your connection in your drizzle config:

```typescript
export default defineConfig({
dialect: "postgresql",
dbCredentials: {
url: "postgres://localhost:5432",
ssl: false,
}
},
});
```

Expand All @@ -98,4 +105,4 @@ export default defineConfig({
## Further Reading

- [pg-gateway](https://github.com/supabase-community/pg-gateway) - Built on top of this project
- [postgres.new](https://supabase.com/blog/postgres-new) - A blog post by Supabase about running Postgres in the browser
- [postgres.new](https://supabase.com/blog/postgres-new) - A blog post by Supabase about running Postgres in the browser
2 changes: 1 addition & 1 deletion examples/pglite-drizzle/src/index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!DOCTYPE html>
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
Expand Down
2 changes: 1 addition & 1 deletion examples/pglite-prisma/src/index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!DOCTYPE html>
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
},
"repository": {
"type": "git",
"url": "https://github.com/f0rr0/pg-browser-proxy"
"url": "git+https://github.com/f0rr0/pg-browser-proxy.git"
},
"funding": {
"type": "github",
Expand Down
8 changes: 4 additions & 4 deletions packages/pg-browser-proxy/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/f0rr0/pg-browser-proxy"
"url": "git+https://github.com/f0rr0/pg-browser-proxy.git"
},
"homepage": "https://github.com/f0rr0/pg-browser-proxy#readme",
"bugs": {
Expand Down Expand Up @@ -73,11 +73,11 @@
"types": "./dist/browser/index.d.ts"
},
"./proxy": {
"import": "./bin/src/proxy.js",
"types": "./bin/src/proxy.d.ts"
"import": "./dist/proxy/proxy.js",
"types": "./dist/proxy/proxy.d.ts"
}
},
"bin": {
"pg-proxy": "./bin/src/cli/bin.js"
"pg-browser-proxy": "bin/bin.js"
}
}
12 changes: 9 additions & 3 deletions packages/pg-browser-proxy/src/cli/help.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,17 @@ const command: GluegunCommand = {
print.info(`
${chalk.bold.blue("🔌 PG Browser Proxy")}
${chalk.blue("A WebSocket-TCP proxy that enables PostgreSQL clients to connect to in-browser databases")}
${chalk.blue(
"A WebSocket-TCP proxy that enables PostgreSQL clients to connect to in-browser databases",
)}
${chalk.bold("Options:")}
-t, --tcp-port <port> TCP port for PostgreSQL clients ${chalk.dim(`(default: ${DEFAULT_CONFIG.tcpPort})`)}
-w, --ws-port <port> WebSocket port for browser connections ${chalk.dim(`(default: ${DEFAULT_CONFIG.wsPort})`)}
-t, --tcp-port <port> TCP port for PostgreSQL clients ${chalk.dim(
`(default: ${DEFAULT_CONFIG.tcpPort})`,
)}
-w, --ws-port <port> WebSocket port for browser connections ${chalk.dim(
`(default: ${DEFAULT_CONFIG.wsPort})`,
)}
-s, --silent Suppress all output
-h, --help Display help
-v, --version Display version
Expand Down

0 comments on commit 7ec4a6b

Please sign in to comment.