I need to model the concept of: “table has multiple fields, each field can have different validation rules based on its type
”.
Not sure what is the best way to achieve this. I have this to start with:
storageType sub attribute, value string;
field sub entity,
owns storageType;
Now, how to model the table has many fields
concept? I did this:
table sub entity,
plays tbl-fld-relation:table,
owns name;
tbl-fld-relation sub relation,
relates table,
relates field,
Question 1:
- Is the above the best way or should I just say:
table sub entity,
owns field;
Question 2:
- How to model:
field has different validation rules based on its type?
For example, if field.storageType == "string"
then that field should have string validation rules
, if field.storageType == "number"
then that field should have number validation rules
etc.
minLength sub attribute, value long;
maxLength sub attribute, value long;
minValue sub attribute, value long;
maxValue sub attribute, value long;
str-validation-rules sub entity,
owns minLength,
owns maxLength;
num-validation-rules sub entity,
owns minValue,
owns maxValue;
How to mix the above kind of validation rules with the field
based on its attributed value?
If it helps, the background is: I am trying to model the Postgres database metadata (the tables, fields, foreign keys, primary kets etc. all
) in TypeDB;
Any help in modelling it correctly would be of great help. Thank you.