timshannon / bolthold

BoltHold is an embeddable NoSQL store for Go types built on BoltDB
MIT License
643 stars 45 forks source link

Constraint pairs #133

Open petermakeswebsites opened 2 years ago

petermakeswebsites commented 2 years ago

I would be delighted to have the ability to have a constraint made from two fields in a struct... Ie, constraint A and B. So that they don't have to be unique individually but have to be unique when as a combined pair.

It seems you guys don't have any kind of guidelines when it comes to contributing - happy to tinker with it myself if you're open to that.

timshannon commented 2 years ago

I welcome PRs. Feel free to tinker away.

If I were designing it, I think I'd treat any unique contraints that have matching tag fields as one unique value in the index:

type User struct {
  Name string `boltholdUnique:"UniqueID"`
  Email string `boltholdUnique:"UniqueID"` 
}

Unique value would be Name+Email. The only issue I see what with that is that struct field order isn't guaranteed, so we'd need to order alphabetically or something.