Skip to content

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 days
2
enums:
3
- name: weekdays
4
values:
5
- value: Sunday
6
- value: Monday
7
- value: Tuesday
8
- value: Wednesday
9
- value: Thursday
10
- value: Friday
11
- value: Saturday
1
enums:
2
- name: contenttype
3
values:
4
- value: text
5
- value: html
6
- value: markdown
7
- name: reaction
8
values:
9
- value: Like
10
- value: Celebrate
11
- value: Support
12
- value: Love
13
- value: Insightful

Enum Table Data

contenttype

Terminal window
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

Terminal window
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)