Skip to content

Postgres range inclusive property lost in JSON format #8471

@kingjerod

Description

@kingjerod

What are you doing?

Querying a Postgres table with a daterange column and returning it as JSON.

const Timeline = Sequelize.define({
   id: {type: Sequelize.INTEGER, primaryKey: true},
   date_range: {type: Sequelize.RANGE(Sequelize.DATEONLY)}
});
const range = [
   {value: new Date(Date.UTC(2017, 0, 1)), inclusive: true},
   {value: new Date(Date.UTC(2017, 6, 1)), inclusive: false},
];
await Timeline.create({id: 1, date_range: range});
const row = await Timeline.findById(1);
console.log(JSON.stringify(row)); // No inclusive property

What do you expect to happen?

When returning the data as JSON, the inclusive data should not be lost.

In the docs, there is this optional format for updating, this would be better because it can be turned into JSON without losing any information:

const range = [
  { value: '2017-01-01', inclusive: false },
  { value: '2017-07-01', inclusive: true },
];

What is actually happening?

The inclusive property is lost. This is because the inclusive property is set on an array, and array properties are not converted into JSON (like Array.length).

{id:1, date_range: ['2017-01-01', '2017-07-01']}

Dialect: postgres
Dialect version: 9.6
Database version: 9.6
Sequelize version: 4.4.3
Tested with master branch: Yes

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: bugDEPRECATED: replace with the "bug" issue type

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions