edgedb/edgedb-go

Name generated query return type

fmoor opened this issue · 2 comments

fmoor commented

Currently edgeql-go generates functions with anonymous structs as return types. This becomes awkward very quickly because the type can't be easily used in the signature of user defined functions or in user defined types.

Instead edgeql-go should generate a named struct type and use the name in generated query function's signature. This would allow the user to use the result type in functions and other types as well as define methods on the result type.

A tentative name for the result type is fmt.Sprintf("%sResult", funcName).

fmoor commented

Perhaps the result type should NOT be named if it is a scalar type like string or int64. If it were named it would usually require casting before use which seems abrasive. It is possible that there are cases when this would be desirable, but it seems much less common.

fmoor commented

Should nested structs be named too? It is also hard to refer to them.

func (r *myQueryResult) ShuflledLinks() ??? {
  l := make(???, len(r.Links))
  copy(l, r.Links)
  shuffleSlice(l)
  return l
}