Traits
Traits are way to group together common features that entities should have, like common fields with validations. Developers apply traits to entities with the inherits
function.
Here is a trait that is built into Data API block, which can be used for any entity. It is defined in the namespace of kisai
and it can be accessed as kisai.id
Trait Definition
1namespace: kisai2traits:3- name: id4 fields:5 - name: id6 type: ulid7 defaultvalue: ulid()8 validations:9 - type: required10 - type: unique11 message: id field needs to be unique12 - type: final13 message: id field cannot be updated
Entity inheriting the trait
The person entity will have an additional field id along with firstname, middlename, lastname and address
1entities:2- name: person3 inherits: kisai.id4 fields:5 - name: firstname6 type: string7 - name: middlename8 type: string9 - name: lastname10 type: string11 - name: address12 type: string
Default traits
All entities created on the kis.ai platform have the below fields, injected. into them through the traits kisai.common
and kisai.softdelete
, as they have the attribute applytoall
set to true
.
Trait | Field | Description |
---|---|---|
kisai.common | createdby | this will have the id of the user creating the current row of the entity |
kisai.common | createdon | this will have the timestamp when the user created the current row of the entity |
kisai.common | updatedby | this will have the id of the user updating the current row of the entity |
kisai.common | updatedon | this will have the timestamp when the user updated the current row of the entity |
kisai.softdelete | deletedby | this will have the id of the user soft deleted the current row of the entity |
kisai.softdelete | deletedon | this will have the timestamp when the user soft deleted the current row of the entity |
YAML Definition of common traits
1traits:2- name: common3 applytoall: true4 fields:5 - name: createdby6 type: string7 defaultvalue: contextget("user")8 validations:9 - type: final10 - type: length11 min: 512 max: 25513 - name: createdon14 type: timestamp15 defaultvalue: currentTimestamp()16 validations:17 - type: final18 - name: updatedby19 type: string20 computed: contextget("user")21 validations:22 - type: length23 min: 524 max: 25525 - name: updatedon26 type: timestamp27 computed: currentTimestamp()28- name: softdelete29 applytoall: true30 fields:31 - name: deletedby32 type: string33 validations:34 - type: writeonce35 - type: length36 min: 537 max: 25538 - name: deletedon39 type: timestamp40 validations:41 - type: writeonce