Skip to content

feat(pg): support ArrayBuffer query parameters - #3857

Open
Aschenbath wants to merge 1 commit into
brianc:masterfrom
Aschenbath:feat/arraybuffer-parameters-3323
Open

Aschenbath wants to merge 1 commit into
brianc:masterfrom
Aschenbath:feat/arraybuffer-parameters-3323

Conversation

@Aschenbath

Copy link
Copy Markdown

An ArrayBuffer passed as a query parameter is currently JSON-stringified to {} instead of sending its bytes. Convert genuine ArrayBuffers to Buffer values, including buffers from another realm and buffers returned by a scalar toPostgres() hook. Serialize ArrayBuffers inside PostgreSQL arrays using the existing binary hex representation. Fixes #3323.

This lets a caller send one packed buffer containing metadata and floating-point payload views directly to a BYTEA column. Existing typed-array and DataView parameters retain their byte offset and length. The parameter-conversion documentation now describes both forms.

Validation on Node 24.22.1 and PostgreSQL 17.11 with SSL:

  • New unit cases: 9 pass; the exact base fails 7 and passes 2 compatibility controls.
  • New live-database integration cases pass in JavaScript and native modes, covering packed data, all byte values, empty buffers, cached prepared queries, cross-realm values, hooks and nested arrays.
  • Full monorepo yarn test passes across all 10 packages. Repository-wide ESLint, changed-JavaScript Prettier checks and TypeScript build pass.
  • Independent review: 10 real database journeys pass; the exact base fails 8 and passes 2 controls. Three actual Cloudflare workerd journeys pass; the exact base fails 2 and passes 1 control. Worker runs used a local runtime configuration with the test database connection settings.
  • The packed pg tarball passes CJS and ESM consumer tests against the database.

Native scalar ArrayBuffer parameters have the same behavior as existing Buffer parameters. The pre-existing libpq limitation in #980 still affects arbitrary binary scalar values, including NUL bytes; this change does not claim to fix that transport limitation. Arbitrary binary payloads were verified with the JavaScript and Cloudflare clients, and binary arrays with both JavaScript and native clients.

Implemented with OpenAI Codex and independently reviewed by a separate Codex agent; no human review is claimed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support sending ArrayBuffer values over the wire

1 participant