-
Notifications
You must be signed in to change notification settings - Fork 301
Accept raw result without parsing JSON #194
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
Comments
It's right along what I just played with regarding sending bytea as binary, the issue is deciding return results as binary or text or mixed. I'll play a bit more with it, but until then you could get a long way simply casting json(b) to text in your query |
You can also override the json types and set the serializer to null which will disable JSON.parse |
I know about this ugly hack )
I can do this, only for some queries, or only settings for the connection? |
Why do you find casting to text ugly? Now I'm curious if there's any overhead compared to skipping JSON.parse 😋 |
|
That sounds reasonable. How about adding the following sql`select 1 as x, 2 as x`.raw() That would resolve to this:
This would help some other requests as well who wanted rows as arrays instead of objects, and allow same named columns to be retrieved. For json like in your example sql`select '{"a":"b"}'::jsonb`.raw() you'd get this: [
[ <Buffer 7b 22 61 22 3a 20 22 62 22 7d> ],
count: 1,
columns: [ { name: 'jsonb', parser: [Function: parse], type: 3802 } ],
command: 'SELECT',
state: { status: 'I', pid: 62208, secret: -1778630945 }
] |
Great, I like your interfaces |
Would you mind trying out the #raw branch to see if it works well for you? |
How about |
Same way :) the methods on a tagged query and an unsafe query are the same: const [[buffer]] = await sql.unsafe('select '{"a":"b"}'::jsonb').raw() |
I checked in my test version: const [[buffer]] = await sql`SELECT '{"key": "value"}'::jsonb`.raw()
console.log(JSON.parse(buffer)) Everything works fine, thanks! P.S. |
I still need some performance improvements around connection handling, but copy from / to works now https://github.com/porsager/postgres/tree/copy |
Hello.
We have many endpoints that do not need to parse the json type and receive it as an object, because these endpoints send this
values
as aJSON.stringify(values)
to the client socket.In this case, two expensive blocked operations,
JSON.parse
andJSON.stringify
, are constantly performed.Ideally, I would like to be able to receive the response in the form of a binary buffer, without parsing json, to send this buffer to the client.
How do you like the idea?
Thanks.
The text was updated successfully, but these errors were encountered: