brianc / node-libpq

Simple, low level native bindings to PostgreSQL's libpq from node.js
112 stars 42 forks source link

Pass buffers as parameters #52

Open lukaslihotzki opened 7 years ago

lukaslihotzki commented 7 years ago

Without this commit, buffers passed as parameters are processed like null-terminated strings.

brianc commented 7 years ago

Hey @lukaslihotzki I appreciate the pull request! Would you be able to provide a test for this? Otherwise I'm not going to be able to accept a patch because the risk of regressions is too high!

Thanks again! ❤️ 😄

lukaslihotzki commented 7 years ago

Writing the test I noticed buffers in results still are passed as hex strings, but passing raw buffers there would require much more refactoring across different libraries (at least node-pg-types and node-libpq) and then everything, including numbers, etc., had to be parsed from binary. At least, this commit makes node-postgres interface consistent (buffers as parameters and buffers as result).

danielgavrilov commented 6 years ago

Is this getting merged? Would be happy to contribute more tests if that's what's holding it back!

We ran into this problem trying to store user-generated CSV files with native bindings on node-postgres. Having a \ (backslash) in a parameter can fail with

ERROR:  invalid input syntax for type bytea

Non-native bindings handle this fine and do exactly the same as this pull request (source).