Closed robx closed 2 years ago
@nikita-volkov any thoughts on this one?
Alternatives might be
jsonBytesLazy
in the libraryPostgreSQL.Binary.Encoding
a direct path for single strict byte strings; I'd be happy to give that a shot if you prefer the approachOoops. Sorry for dragging on this. I'll get back to you in the coming days
Please check out the commit above. It adds lazy variations of json functions. If all is fine, I'll make a release.
Please check out the commit above. It adds lazy variations of json functions. If all is fine, I'll make a release.
It looks perfect!
(I'm in the process of updating the corresponding PostgREST PR with the required dependency updates to verify this in CI, but it should be good to go.)
Cool. Released as 1.6.1
It seems the build is broken:
library/Hasql/Private/Encoders.hs:236:17: error:
• Couldn't match type ‘LazyByteString.ByteString’
with ‘ByteString’
NB: ‘ByteString’ is defined in ‘Data.ByteString.Internal’
‘LazyByteString.ByteString’
is defined in ‘Data.ByteString.Lazy.Internal’
Expected type: Value ByteString
Actual type: Value LazyByteString.ByteString
• In the expression:
Value (Value.unsafePTIWithShow PTI.json (const A.json_bytes_lazy))
In an equation for ‘jsonLazyBytes’:
jsonLazyBytes
= Value
(Value.unsafePTIWithShow PTI.json (const A.json_bytes_lazy))
|
236 | jsonLazyBytes = Value (Value.unsafePTIWithShow PTI.json (const A.json_bytes_lazy))
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
(see https://github.com/PostgREST/postgrest/runs/8247544920?check_suite_focus=true)
Oops. Forgot to check the build :) Fixed in 1.6.1.1
As an alternative to #146, this provides a way for users to provide arbitrary custom value encoders, via
Concretely, this addresses the desire within PostgREST to encode JSON directly from a lazy bytestring. The use would be to replace
with
to avoid a copy.
Supposing the general approach seems acceptable, some things I'm unsure about:
Hasql.Encoders.Internal
so that it's clear there should be no expectation of stability?Binary
. Both of these could be relaxed, effectively exposing unsafePTIWithShow.LibPQ.Oid
? I went with it because it's already a public type...