ozzo-dbx icon indicating copy to clipboard operation
ozzo-dbx copied to clipboard

PK in field tag: wrong order?

Open kPshi opened this issue 8 years ago • 3 comments

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?

kPshi avatar Jul 14 '17 18:07 kPshi

Did you encounter any particular problem with the current ordering?

qiangxue avatar Jul 18 '17 17:07 qiangxue

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.

kPshi avatar Jul 19 '17 08:07 kPshi

For example https://github.com/jmoiron/sqlx is confused by that.

kPshi avatar Sep 01 '17 19:09 kPshi