最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Sequelize.INTEGER vs DataTypes.INTEGER - Stack Overflow

programmeradmin1浏览0评论

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?

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?

Share Improve this question edited Oct 5, 2020 at 10:56 Aryan 3,6485 gold badges23 silver badges46 bronze badges asked Jul 21, 2017 at 10:39 musicformellonsmusicformellons 13.5k5 gold badges57 silver badges94 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 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.

发布评论

评论列表(0)

  1. 暂无评论