Skip to content

Add enum type #13

@Didas-git

Description

@Didas-git

I saw this issue on the official redis-om repository (here: redis/redis-om-node#86) and got a bit confused.

Today while writing some code i got an idea on how to do it that i will probably implement in the future:

// create a enum on the schema
somefield: {
    type: "enum",
    fields: [
        "FieldWithValue0",
        "FieldWithValue1",
        // You could also use strings as values
        { FieldWithValue300: 300 },
        "FieldWithValue301"
    ]
}

// using it (this is the complicated part)
// the database would return a number which would need to be mapped back

const data = await model.get(someId)
data.somefield // this is a number (lets say 1 for the sake of the example)

// this is how you would map it back
model.enums.somefield[data.somefield] // returns "FieldWithValue1"

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions