Sequelize.INTEGER vs DataTypes.INTEGER
Asked Answered
A

1

6

In code from 2016 using sequelize ORM, I see model types defined with this pattern:

 module.exports = function(sequelize, DataTypes) {
     const Tasks = sequelize.define("Tasks", {  id: {
       type: DataTypes.INTEGER,
       [ ...etc.]

However in the current sequelize docs you see most prominently documented: Sequelize.INTEGER (or other type then integer). At the same time in the current docs I find also DataTypes still documented/used: here.

On same page the Sequelize.INTEGER is used..., is that only for deferrables or something?

I tried to find whether this altered over time or something but could not find it.

When Sequelize.INTEGER is 'current solution' could I just alter above code into:

module.exports = function(sequelize, Sequelize) {
  const Tasks = sequelize.define("Tasks", {  id: {
    type: Sequelize.INTEGER,
    [ ...etc.]

Or would using Sequelize as argument somehow make this fail?

Anadromous answered 21/7, 2017 at 10:39 Comment(0)
S
4

The second parameter in both of them is just the sequelize package itself You can use any of them which is on you what you want to use

const Sequelize = require('sequelize');

You'll notice in your index.js of models (if you set up as suggested) that you do something like the below, where you are passing in sequelize as the second argument.

const model = require(path.join(__dirname, file))(sequelize, Sequelize);

This exposes the data types. It doesn't matter what you call it. For example I am calling it abc in below code you can use any name

module.exports = (sequelize, abc) => {
  const Driver = sequelize.define('Driver', {
  firstName: {
       type: abc.STRING(),
       allowNull: false
  },
  last_name: {
       type: abc.TEXT,
       allowNull: true
  },
  email: {
      type: abc.TEXT,
      allowNull: false
  },
  password: {
      type: abc.TEXT,
      allowNull: true
  }

Same with migrations.

Scarabaeoid answered 7/10, 2020 at 10:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.