Enums
Enums, short for “enumerations,” are a data type in many programming languages that consist of a set of named values called elements or members. These named values represent fixed, distinct, and related items within a collection, making the code more readable and maintainable by providing meaningful names instead of numeric or string literals.
Here enums allow developers to define list of values. Entities can have one more fields with data type as enum. A table is created for each enumeration with id and string value. The entity table will have the id of the enum instead of the string value.
1# enum for week days2enums:3- name: weekdays4 values:5 - value: Sunday6 - value: Monday7 - value: Tuesday8 - value: Wednesday9 - value: Thursday10 - value: Friday11 - value: Saturday
1enums:2 - name: contenttype3 values:4 - value: text5 - value: html6 - value: markdown7 - name: reaction8 values:9 - value: Like10 - value: Celebrate11 - value: Support12 - value: Love13 - value: Insightful
Enum Table Data
contenttype
id | value | createdby | createdon | updatedby | updatedon | deletedby | deletedon----+----------+-------------+------------------------+-------------+------------------------+-----------+----------- 1 | text | dataservice | 2024-02-22 13:56:40+00 | dataservice | 2024-02-22 13:56:40+00 | | 2 | html | dataservice | 2024-02-22 13:56:40+00 | dataservice | 2024-02-22 13:56:40+00 | | 3 | markdown | dataservice | 2024-02-22 13:56:40+00 | dataservice | 2024-02-22 13:56:40+00 | |(3 rows)
reaction
id | value | createdby | createdon | updatedby | updatedon | deletedby | deletedon----+------------+-------------+------------------------+-------------+------------------------+-----------+----------- 1 | Like | dataservice | 2024-02-22 13:56:40+00 | dataservice | 2024-02-22 13:56:40+00 | | 2 | Celebrate | dataservice | 2024-02-22 13:56:40+00 | dataservice | 2024-02-22 13:56:40+00 | | 3 | Support | dataservice | 2024-02-22 13:56:40+00 | dataservice | 2024-02-22 13:56:40+00 | | 4 | Love | dataservice | 2024-02-22 13:56:40+00 | dataservice | 2024-02-22 13:56:40+00 | | 5 | Insightful | dataservice | 2024-02-22 13:56:40+00 | dataservice | 2024-02-22 13:56:40+00 | |(5 rows)