neo4j/neo4j-go-driver

Struct to map for query parameters

Tak1za opened this issue · 1 comments

While trying to execute a cypher query with parameters being passed as a map[string]interface{}.
The problem is converting from a struct to a map by using the unmarshaller, it's converting an int value to a float64.

The documentation of json from docs clearly state:

 To unmarshal JSON into an interface value, Unmarshal stores one of these in the interface value:

bool, for JSON booleans
float64, for JSON numbers
string, for JSON strings
[]interface{}, for JSON arrays
map[string]interface{}, for JSON objects
nil for JSON null

Which is causing a problem as my passed integer value is being stored as a float inside neo4j.

There clearly should be a workaround, but I'm not able to figure it out.

Unfortunately, JSON is not a good candidate since it does not differentiate floats and integers.
The way I would personally go about it would be to manually create the query parameter map all the time.
If that feels to repetitive, you can instead define a function that uses reflection to introspect the struct fields and create the corresponding map.

NOTE: this kind of usage question is more suited to https://community.neo4j.com. GitHub issues are mostly about potential bugs with the driver.