ozzo-dbx
ozzo-dbx copied to clipboard
PK in field tag: wrong order?
struct.go:
| 217 | func parseTag(tag string) (string, bool) {
| 218 | if tag == "pk" {
| 219 | return "", true
| 220 | }
| 221 | if strings.HasPrefix(tag, "pk,") {
| 222 | return tag[3:], true
| 223 | }
| 224 | return tag, false
| 225 | }
Requires "pk" to be the first part in a db tag. Shouldn't it be the second word or maybe any word to be consistent with e.g. "omitempty" in a json tag?
Did you encounter any particular problem with the current ordering?
Actually only during experimenting with different storage methods which then tended to call the field "pk". Of course I can just change the tag definition then but I find it a bit confusing and inconsistent that the struct has to know which engine it is stored with. And forcing pk to be the first element seems to be uncommon when comparing it to json tag.
Long story short: it's a minor issue only.
For example https://github.com/jmoiron/sqlx is confused by that.