Sequelize ORM map/dictionary/hash-map

Viewed 34

Is it possible to save a map/dictionary of string - integer pairs in a PostGres database?

Take the following example that maps items by their stock amount:

{
        "mtvrcargo1door": 0,
        "ext_uh1y": 0,
        "booniehat_blue": 1,
        "canvas_backpack_red": 1,
        "dirtbikehelmet_khaki": 0,
}

I've looked across the data-types documentation but couldn't find anything specifically for dictionaries. I feel like my best bet is using the JSONB data-type, but I'm posting here just in case there's something I'm missing here, as JSONB would also check valid for an array of dictionaries.

1 Answers

As you already assumed your best match is JSONB and it would be your responsibility to validate the content of this column.
Maybe you can add some constraint for this column using JSONB functions in DB to check if a value that is about to be saved is a dictionary.

Related