4 ms·
There are times this makes sense to do (mapping an enum to a db without enum support eg mssql) but this isn’t how I’d do it. Personally I use stringer[1] to ha
by sugarpile 6y ago
There are times this makes sense to do (mapping an enum to a db without enum support eg mssql) but this isn’t how I’d do it.
Personally I use stringer[1] to handle all the string generation and then implement the valuer and scanner interfaces on that type. Boom transparent mapping between useful values and their corresponding db representation without having to write so much boilerplate.
[1] https://pkg.go.dev/golang.org/x/tools/cmd/stringer https://pkg.go.dev/golang.org/x/tools/cmd/stringer