Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Serialize arrays of Uint8Array objects as hex escape sequences #2930

Merged
merged 1 commit into from Feb 10, 2024

Conversation

sds
Copy link
Contributor

@sds sds commented Mar 13, 2023

Previously, if you attempted to pass an array of Uint8Array objects to a prepared statement, it would render each literal numeric value of that array.

Since Uint8Array (and other TypedArray types) represent views over raw bytes, ensure these are serialized to Postgres as bytes via hex escape sequence.

Previously, if you attempted to pass an array of `Uint8Array` objects to
a prepared statement, it would render each literal numeric value of that
array.

Since `Uint8Array` (and `TypedArray` types) represent views over raw
bytes, ensure these are serialized to Postgres as a byte representation.
@sds sds force-pushed the sds/handle-array-of-uint8array branch from 8bf3f4c to a5f631c Compare March 13, 2023 23:30
packages/pg/lib/utils.js Show resolved Hide resolved
packages/pg/lib/utils.js Show resolved Hide resolved
@sds
Copy link
Contributor Author

sds commented Mar 15, 2023

Thanks for the review, @charmander.

Would you like me to combine your recommendations into this PR, or would you prefer those changes be made in separate PRs? Happy to make the additional changes, just looking for confirmation. Thanks!

@sds
Copy link
Contributor Author

sds commented Mar 21, 2023

Polite ping, @charmander. Let me know if we'd like your requested changes combined into a single PR, or implemented in separate PRs. Happy to do so once I get clarity on preference. Thanks!

@charmander
Copy link
Collaborator

Yep, don’t worry about it, a separate PR is better and I can take care of that.

@sds
Copy link
Contributor Author

sds commented Jan 31, 2024

Just checking in on this—was there anything in particular blocking this PR?

SevInf added a commit to prisma/prisma that referenced this pull request Feb 9, 2024
…f Buffers

We want to stop using `Buffer` on the engine side and eventually, got
rid of polyfill.
However, due to a bug in pg (neon also inherits it), typed arrays are
not encoded correctly when used inside of the lists.

See brianc/node-postgres#2930

This PR hacks around it by converting typed arrays into lists of Buffers
that are encoded correctly.

Contributes to prisma/team-orm#931
@SevInf
Copy link

SevInf commented Feb 9, 2024

We've just stumbled upon this bug in Prisma too and would like to see this merged. @charmander is there any way we could help? If there are some changes need we can spend some time on it.

@charmander
Copy link
Collaborator

charmander commented Feb 10, 2024

(Is it really a bug if typed arrays didn’t exist in Node back when the code was written?)

Anyway, I’ll merge this for convenience, but it’s up to @brianc to release it. (semver patch)

@charmander charmander merged commit 81c287a into brianc:master Feb 10, 2024
15 checks passed
@SevInf
Copy link

SevInf commented Feb 10, 2024

(Is it really a bug if typed arrays didn’t exist in Node back when the code was written?)

Singular typed array is correctly encoded by pg since 2017, only a list of typed arrays is not until this PR.

@charmander charmander added the bug label Feb 10, 2024
SevInf added a commit to prisma/prisma that referenced this pull request Feb 12, 2024
…f Buffers (#23047)

We want to stop using `Buffer` on the engine side and eventually, got
rid of polyfill.
However, due to a bug in pg (neon also inherits it), typed arrays are
not encoded correctly when used inside of the lists.

See brianc/node-postgres#2930

This PR hacks around it by converting typed arrays into lists of Buffers
that are encoded correctly.

Contributes to prisma/team-orm#931
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants