Enumerators are a set of unique names coupled to a unique set of values. ThingsDB support enumerators for type int, float, str, bytes and thing, where all members must have the same type. Thus, it is not possible to have an enum type with for example both values of type int and str. Enumerators with type thing may contain things using different Type as each instance of a Type is still a thing.


Function Description
name Return the name of the enum member.
value Return the value of the enum member.
Function Description
del_enum Delete an enumerator type.
enum Get an enum member by value.
enum_info Return info about the enumerator type.
enums_info Return info about all the enumerator types in the current scope.
has_enum Determine if the current scope has a given enumerator type.
isenum Test if a given value is a member of an enumerator type.
mod_enum Modify an existing enumerator type.
set_enum Create a new enumerator type.


// Create an enumeration type using `set_enum`
set_enum('Severity', {
    CRITICAL: 1,
    MAJOR: 2,
    MINOR: 3,
    DEBUG: 4,

// Get a member by name
a = Severity{CRITICAL};

// Get a member by value
b = Severity(2);  // MAJOR

// Dynamically by name
c = Severity{||'MINOR'};

// Or, dynamically both by name and value
d = enum('Severity', 4);  // DEBUG

// Variable `a`, `b`, `c` and `d` are all members of type `Severity`
type_assert(a, 'Severity');
type_assert(b, 'Severity');
type_assert(c, 'Severity');
type_assert(d, 'Severity');

// The actual value can be accessed via the `.value()` function
assert( b.value() == 2 );

// Or, the name can be returned using the `.name()` function
assert( c.name() == 'MINOR');

// The value of the members will be returned in a response
[a, b, c, d];

Return value in JSON format