go-driver
go-driver copied to clipboard
[Request] Add cursor method that returns RAW JSON
As the reposnse of a query it's already in JSON format and sometimes it's only required to forward the results, Marshal and Unmarshal the results it's a waste of resources.
I agree. Having the choice to either get the raw JSON or the processed struct/map would be useful in some cases.
Having just looked at that code path, the entire response from the server is JSON, so Unmarshaling has to happen for the driver to handle the response. So while the driver could add a "ReadDocumentAsJSON" method, it would just be an added re-Marshal, which defeats the purpose.
Also, you could just call the API directly for situations where you want raw access; the HTTP API is fairly well documented and straightforward.
Having just looked at that code path, the entire response from the server is JSON, so Unmarshaling has to happen for the driver to handle the response. So while the driver could add a "ReadDocumentAsJSON" method, it would just be an added re-Marshal, which defeats the purpose.
That's not totally true, the response it's json but you can read the header only and not the result, so you don't need to fully marshal and unmarshal everything.
Also, you could just call the API directly for situations where you want raw access; the HTTP API is fairly well documented and straightforward.
I know , this library it's just a wrapper for the HTTP API, so it should support return the raw results if requested.
with raw json we can use another json codec/serde ...
with raw json we can use another json codec/serde ...
While there are niche cases for alternative serdes, I've never seen compelling overall alternatives, and certainly the field of options is more limited in Go. If the idea is to optimize away at the µs level, using a driver to simply tunnel a REST response seems to defeat the purpose.
This might make sense for a one-off API call requirement for direct JSON access—continuing to use the driver rather than spinning up a separate HTTP client just for that call—but even then I feel there are offsetting pros and cons.
Generally and from a Go ethos perspective, I'd personally have a hard time justifying the work and ongoing maintenance complexity, IMHO. (Obviously it's Arango's decision, and neither case is wrong per se.)
Currently, we provide an option to load a response to any struct which could be even a simple map[string]interface{}
:
https://github.com/arangodb/go-driver/blob/a0bb2e36e37399a0d5e7a893e01dc29a823363fc/v2/arangodb/cursor.go#L44-L44
Also, there is a BatchCursor, which lets to load multiple docs at once: https://github.com/arangodb/go-driver/blob/a0bb2e36e37399a0d5e7a893e01dc29a823363fc/v2/arangodb/cursor.go#L61-L62
If the raw response is needed then, as suggested by @irridia, please use raw HTTP request.