gremgo icon indicating copy to clipboard operation
gremgo copied to clipboard

Request: return struct instead of interface{}

Open bobvanluijt opened this issue 6 years ago • 2 comments

For example the function: ExecuteStruct(...) = same as Execute(...) but a result as a struct rather than an interface.

Reason for request: sometimes the structure is known and this makes it easier to handle.

Full example:

type Edges [][]struct {
	ID         int    `json:"id"`
	InV        int    `json:"inV"`
	InVLabel   string `json:"inVLabel"`
	Label      string `json:"label"`
	OutV       int    `json:"outV"`
	OutVLabel  string `json:"outVLabel"`
	Properties struct {
		LocationURL string `json:"locationUrl"`
		Type        string `json:"type"`
	} `json:"properties"`
	Type string `json:"type"`
}

var edges *Edges

err := f.client.ExecuteStruct(
	         "SOME-TINKERPOP-QUERY",
	        &edges,
		map[string]string{"uuid": UUID.String()},
		map[string]string{},
	)

bobvanluijt avatar Jul 06 '18 10:07 bobvanluijt

I think returning a []][]byte, where each element contains a byte slice containing the JSON result for the request, would also be nice. The thing it does now with returning an interface{} makes the library a pain in the ass to use. Users should be able to unmarshal the response however they way.

slnt avatar Oct 11 '18 20:10 slnt

Sure, same solution from a different angle.

bobvanluijt avatar Oct 12 '18 06:10 bobvanluijt