node-postgres icon indicating copy to clipboard operation
node-postgres copied to clipboard

Support sending ArrayBuffer values over the wire

Open s-devaney opened this issue 1 year ago • 3 comments

PG supports sending ArrayBuffer views (e.g. TypedArray instances like Uint8Array) over the wire as values in queries, but it cannot send the underlying ArrayBuffer as a value.

Use case: I have one ArrayBuffer which represents packed binary data, it containing multiple TypedArray views e.g. one UInt8Array for meta data and one Float32Array containing a payload.

I want to insert this entire ArrayBuffer into a Postgres BYTEA column.

But, currently, the PG prepareValue util function does not support preparing ArrayBuffer values.

Preparing an ArrayBuffer is a simple change, it can just be converted to a Buffer by simply passing it to Buffer.from()

s-devaney avatar Sep 30 '24 14:09 s-devaney

Yes, I was wondering the same thing. Having something that do not depend on node:Buffer would be great - and also runtime agnostic. Using ArrayBuffer would make it Deno compatible for bytea columns. E.g. Cloudflare D1 uses ArrayBuffer

lroal avatar Feb 15 '25 10:02 lroal

@lroal You can use new Uint8Array(arrayBuffer) in pg right now.

charmander avatar Mar 04 '25 23:03 charmander

@lroal You can use new Uint8Array(arrayBuffer) in pg right now.

But this is only for incoming ? (inserts) Not for selects ?

lroal avatar Mar 05 '25 07:03 lroal