A column of type enum
can take a value from a list of valid values explicitly listed in the column specification when you create a table.
An example of creating a Status (status
) field in the Tasks (tasks
) table:
Field name | Type | Is Nullable | Is Immutable | Default |
---|---|---|---|---|
stage | enum('backlog', 'new', 'in_progress', 'done') |
false |
false |
'new' |
The list of field values can be obtained from an FunQL query using the construction
SELECT value
FROM DOMAIN OF FIELD pm.tasks.status as statuses
The result of this query for the example above:
statuses.value |
---|
backlog |
new |
in_progress |
done |
Listing values separated by commas:
SELECT string_agg(value, ', ') as lst
FROM DOMAIN OF FIELD pm.tasks.status as statuses
statuses.lst |
---|
'backlog', 'new', 'in_progress', 'done' |
Attributes (field_attributes
) can be assigned to each enum value using mapping
. Attribute names can be arbitrary (within valid names)
@{
attribute = mapping
WHEN 'enum_val1' THEN 'attr_value1'
WHEN 'enum_val2' THEN 'attr_value2'
-- ...
END
}
tasks.status
field attributes:
@{
-- Field attributes --
caption = 'Status',
soft_disabled = is_archived,
text_align = 'center',
cell_variant = CASE WHEN is_archived THEN 'light' END,
-- Values attributes --
option_variant = mapping
WHEN 'backlog' THEN 'outline-secondary'
WHEN 'new' THEN 'outline-info'
WHEN 'in_progress' THEN 'outline-warning'
WHEN 'done' THEN 'outline-success'
END,
icon = mapping
WHEN 'backlog' THEN 'lightbulb'
WHEN 'new' THEN 'flag'
WHEN 'in_progress' THEN 'notifications'
WHEN 'done' THEN 'done_all'
END,
order_number = mapping
WHEN 'backlog' THEN 3
WHEN 'new' THEN 1
WHEN 'in_progress' THEN 2
WHEN 'done' THEN 4
END
}
text
The text
attribute replaces the caption for each of the enum values - sets the "title" that will be displayed in the user interface.
@{
text = mapping
WHEN 'backlog' THEN 'Ideas'
WHEN 'new' THEN 'New'
WHEN 'in_progress' THEN 'In progress'
WHEN 'done' THEN 'Done'
END
}
В случаях, где необходимо установить атрибуты для поля, являющегося "массивом перечислимых значений" (array(enum('backlog', 'new', 'in_progress', 'done'))
) вместо mapping
используется array mapping
:
array mapping
is used instead of mapping
in cases where you need to set attributes for a field that is an "array of enumerated values" (array(enum('backlog', 'new', 'in_progress', 'done'))
) :
{
$status array(enum('backlog', 'new', 'in_progress', 'done')) null @{
caption = 'Status',
text = array mapping
WHEN 'backlog' THEN 'Ideas'
WHEN 'new' THEN 'New'
WHEN 'in_progress' THEN 'In progress'
WHEN 'done' THEN 'Done'
END
}
}:
SELECT id
FROM pm.tasks
WHERE ($status IS NULL OR status = ANY($status))
Ozma supports operators .@
and .@@
that allow you to get the values of field and entity attributes, respectively.
SELECT @type='board',
status.@text as status @{
option_variant = status.@option_variant,
icon = status.@icon
},
subject,
due_date,
status as s @{
visible = false,
board_group = true
},
FROM pm.tasks
ORDER BY status.@order_number
status.@text
- returns 'New' for entries in new
status, 'In Progress' for entries in in_progress
status, etc.status.@icon
, status.@option_variant
and status.@order_number
- return attribute values corresponding to the specified record status