samedi 18 avril 2020

Recommendations for database schema/data structure for picking default value given a list

Sorry for the vague title.

We have a use case where we can get 0 to many roles and from that list we need to set a "default value"

For instance say we scan the text of a document (doc 1) for roles, and we find role x, y , z and another document (doc b) we find roles a, b , y. And a third document (doc 2) we find role y.

We have a bussines rule that says if we find roles x, y, z all together choose z. If we find x, z together return no default. If we find a, choose a, regardless of what other roles are with it. And if we find just one role, default to that role.

If the rules were hard and fast I could easily just make this as a giant switch statement, or something in code, but things can change on the fly so I would like to store this in a database or something that so that I can just do something along the lines of:

    PsuedoSelectDefault(Inputs[])
      If inputs.length == 0
        Return ""
      Else of inputs.length == 1
        Return inputs[0]
      Else 
       Return RunSomeSql(Inputs)
       // Where RunSomeSql choses the default for me.

But I'm at a lost for how this database Shou be structured.

I'm assuming this isn't a new problem but I'm not sure what sort of key words I should be looking for.

If anyone can point me in the right direction it would be greatly appreciated.

Aucun commentaire:

Enregistrer un commentaire