How does it magically use {} or [] for arrays? #939
-
Hi @porsager I've been studying this code for about 6 hours and I have a massive headache. Please put me out of my misery and tell me how you are doing this magic. Somehow this library can encode jsonb arrays and native arrays from JS arrays perfectly depending on the context. For example, here I am inserting data into a jsonb column and text[] column: sql`insert into users (data, arr) values (${['yolo', 'gg']}, ${['hello', 'world']})` which results in this:
Even though I used a JS array for both parameters in my code, this library magically converts the second parameter to a native array while the first one uses jsonb. HOW? I am trying to get pglite working properly but running into this issue. electric-sql/pglite#220 (comment) Please end my suffering. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
https://www.postgresql.org/docs/current/protocol-flow.html#PROTOCOL-FLOW-EXT-QUERY If you wait for the |
Beta Was this translation helpful? Give feedback.
https://www.postgresql.org/docs/current/protocol-flow.html#PROTOCOL-FLOW-EXT-QUERY
https://www.postgresql.org/docs/current/protocol-message-formats.html
If you wait for the
ParameterDescription
message before issuingBind
, you can use that to decide how to serialize you parameters.