estus estus - 4 months ago 39
Node.js Question

Sequelize range Timeline.create

Where does

Timeline.create
come from in the manual?

// empty range:
Timeline.create({ range: [] }); // range = 'empty'

// Unbounded range:
Timeline.create({ range: [null, null] }); // range = '[,)'
// range = '[,"2016-01-01 00:00:00+00:00")'
Timeline.create({ range: [null, new Date(Date.UTC(2016, 0, 1))] });

// Infinite range:
// range = '[-infinity,"2016-01-01 00:00:00+00:00")'
Timeline.create({ range: [-Infinity, new Date(Date.UTC(2016, 0, 1))] });


I fail to find anything on
Timeline
.

Answer

It's just an example model name. It would be defined something like this:

var Timeline = sequelize.define('Timeline', {
  range: Sequelize.RANGE(Sequelize.DATE),
  // [... some other columns here]
});

You can then create instances and pass two values (lower, upper) for that range column:

Timeline.create({
  range: [
    new Date(Date.UTC(2016, 0, 1)), // lower
    new Date(Date.UTC(2016, 1, 1))  // upper
  ]
});

(create() is a standard method of sequelize models. It creates an in-memory instance of a class - Timeline in this case, but it could be Person, Car, Octopus or anything else - and then saves it to the database table that model represents.)

Comments