arangodb / go-driver

The official ArangoDB go driver.
Apache License 2.0
339 stars 79 forks source link

Use unique struct comment tag name #44

Open ftKnox opened 7 years ago

ftKnox commented 7 years ago

It would be beneficial and make it more inline with many other go drivers for other databases to use a unique name for the json marshal/unmarshalling. One specific use case is have a particular field used as a query field but I don't want that field saved to the database. In the example below i may have an http request with "parent_container_id" populated to have it search for a particular container, but I don't need that data saved into arangodb. So currently I am forced to build an additional struct just to omit that field.

type Container {
 ID string `json:"_key"`
}
type Item {
  *Container `json:"container"`
  ParentContainerID string `json:"parent_container_id"`
}

// something like this would be preferable
type Item {
  *Container `json:"container"`
  ParentContainerID string `arangodb:"-" json:"parent_container_id"`
}
ewoutp commented 7 years ago

Let me see if I understand you correctly. You want an additional tag that overwrites the json tag when both exist. Right?

I assume the semantics of that tag should be identical to the json tag.

If so. This is something that we have been discussing. I'll revive that discussion.

ftKnox commented 7 years ago

Yeah it's how the gorethink and mgo drivers work for rethinkdb and mongodb.