go-driver icon indicating copy to clipboard operation
go-driver copied to clipboard

[Request] Add cursor method that returns RAW JSON

Open OrlandoCo opened this issue 4 years ago • 5 comments

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.

OrlandoCo avatar Apr 15 '20 20:04 OrlandoCo

I agree. Having the choice to either get the raw JSON or the processed struct/map would be useful in some cases.

camba1 avatar Jun 24 '20 15:06 camba1

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.

irridia avatar Oct 01 '20 05:10 irridia

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.

OrlandoCo avatar Oct 01 '20 18:10 OrlandoCo

with raw json we can use another json codec/serde ...

aKorsi avatar Mar 28 '21 11:03 aKorsi

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.)

irridia avatar Mar 29 '21 10:03 irridia

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.

jwierzbo avatar Jul 26 '23 13:07 jwierzbo