【问题标题】:how to set sequalize postgres model type for inet?如何为inet设置sequelize postgres模型类型?
【发布时间】:2019-11-15 17:30:48
【问题描述】:

我正在使用sequelize ORM 来管理 postgress 数据库。

在我的 postgress 数据库中,我们使用数据类型 inet 来存储 IPv4、IPv6 值。

当我在 sequelize 中创建模型时,我无法在 sequelize 中找到 inet 类型。

我可以在 sequelize 中使用什么来代替 inet 来创建模型?

const User = sequelize.define(
  'User',
  {
    email: {
      type: Sequelize.STRING,  /*postgres varchar data type*/
      unique: true,
    },
    encrypted_password: {
      type: Sequelize.STRING,  /*postgres varchar data type*/
      allowNull: false,
    },
    last_login_ip: {
      type:  ?,   /*postgres inet data type*/
    }
  }
);

【问题讨论】:

    标签: javascript node.js postgresql orm sequelize.js


    【解决方案1】:

    新版本支持 INET 数据类型(注意它仅适用于 Postgres)。 https://sequelize.org/master/class/lib/data-types.js~INET.html

    const User = sequelize.define(
      'User',
      {
        email: {
          type: Sequelize.STRING,  /*postgres varchar data type*/
          unique: true,
        },
        encrypted_password: {
          type: Sequelize.STRING,  /*postgres varchar data type*/
          allowNull: false,
        },
        last_login_ip: {
          type: Sequelize.INET,   /*postgres inet data type*/
        }
      }
    );
    

    【讨论】:

      【解决方案2】:

      最新版本的 sequelize 支持 INET 数据类型。 https://sequelize.org/master/manual/data-types.html

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2020-01-23
        • 1970-01-01
        • 2019-11-03
        • 1970-01-01
        • 2018-11-24
        • 1970-01-01
        • 2019-04-15
        相关资源
        最近更新 更多