Home > other >  How to save values in column type range in postgres using Sequelize?
How to save values in column type range in postgres using Sequelize?

Time:01-25

I have a model where I have a column name data_numbers and its type is DataTypes.RANGE(sequelize.INTEGER) I am using the following line of code to create a new row in table models.TABLE.create({ data_numbers: ?? //here is what I should write to save a range of numbers. })

CodePudding user response:

Here you go. While saving data in column type range you have to assign an array of Range type, like following

const TABLE = sequelize.define(
    "table",
    {
      data_numbers: DataTypes.RANGE(sequelize.INTEGER),
    },
    {
      underscored: true,
      paranoid: true,
      defaultScope: {
        attributes: [
          "id", 
          "data_numbers",
        ],
      },
    }
  );

and while creating new object I added value like following

models.TABLE.create({
    data_numbers: [1, 199]
})
  •  Tags:  
  • Related