Using Enums

Enumerated types are declared using the ENUM() statement. You must declare the acceptable enumeration values when you use this statement.

To define a simple two-field table where the primary key is a UID and the second field contains an enum, you use the following DDL statement:

CREATE TABLE myTable (
    uid INTEGER,
    myEnum ENUM (Apple,Pears,Oranges),
    PRIMARY KEY (uid)
) 

CHECK constraints are not supported for enumerated fields.

DEFAULT and NOT NULL constraints are supported for enumerated fields. See DEFAULT for more information.

Enum values are handled as strings.

To write the enum:

  var row = {uid: 0,
             myEnum: 'Pears',
             };

   store.put('myTable', row,
           function (err) {
                if (err)
                    throw err;
                else {
                    console.log("Row inserted.");
                }
           }); 

To read the enum:

  var primaryKey = {uid: 0};
   store.get('myTable', primaryKey,
           function (err, returnRow) {
                if (err)
                    throw err;
                else {
                    // returns as a string
                    console.log('myEnum: ' + returnRow.currentRow.myEnum);
                    store.close();
                }
           });