Clarify pglite-server TCP and Unix socket connection examples#1042
Clarify pglite-server TCP and Unix socket connection examples#1042compair-steven wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e34b49b45b
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| When using `--run` with `--include-database-url`, you can use the generated `DATABASE_URL`: | ||
|
|
||
| ```javascript | ||
| const sql = postgres(process.env.DATABASE_URL) |
There was a problem hiding this comment.
Don't point postgres.js at the socket DATABASE_URL
In the Unix-socket flow, createDatabaseUrl() emits a libpq-style URL like postgresql://postgres:postgres@/postgres?host=/tmp for --path (packages/pglite-socket/src/scripts/server.ts:146), but postgres.js does not use the host query parameter to choose a Unix socket; the repo's own postgres.js socket test uses the path option instead. An app following this example with --path and --include-database-url will try the default TCP host (or hit another server) rather than the PGlite socket, so this should either stay scoped to clients that understand that URL form or show how to pass path to postgres.js.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Good catch, and thanks for the prompt review. I just updated this section to avoid suggesting that postgres.js can consume the generated libpq-style Unix socket DATABASE_URL directly. It now keeps the generated URL scoped to clients that understand ?host=/tmp and points postgres.js users back to the path option.
Hopefully this addresses the concern!
Summary
Clarifies the
pglite-serverconnection examples by separating the default TCP listener from Unix socket connections.The README introduces Unix socket support with
--pathand shows the generated socket-styleDATABASE_URL, but the followingpsqland Node.js examples uselocalhost:5432, which applies to the default TCP listener. Since--pathtakes precedence over host/port, reading those examples sequentially can make it look likelocalhost:5432should connect to the Unix socket server.This keeps both setup paths documented and adds explicit Unix socket examples for
psql,node-postgres, andpostgres.js.Validation
pnpm -C packages/pglite-socket buildpnpm exec prettier --check packages/pglite-socket/README.mdpglite-serverwith--path, creating a sentinel table through the generated Unix socket connection string, and checking that the TCP-stylelocalhost:5432example did not reach that server while the socket-style URL did.