-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Serialize arrays of Uint8Array objects as hex escape sequences #2930
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
Conversation
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.
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! |
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! |
Yep, don’t worry about it, a separate PR is better and I can take care of that. |
Just checking in on this—was there anything in particular blocking this PR? |
…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
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. |
(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) |
Singular typed array is correctly encoded by |
…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
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 otherTypedArray
types) represent views over raw bytes, ensure these are serialized to Postgres as bytes via hex escape sequence.