简体   繁体   English

重命名node.js sequelize timestamp列

[英]Rename node.js sequelize timestamp columns

I've just started using sequelize but I'm having a small issue mapping an existing database. 我刚刚开始使用sequelize但是我有一个小问题映射现有数据库。

By default sequelize creates two datatime columns named createdAt and updatedAt, does anyone know if its possible to rename the columns to something else. 默认情况下,sequelize会创建两个名为createdAt和updatedAt的数据时间列,是否有人知道是否可以将列重命名为其他内容。 For example... 例如...

products: sequelize.define('products', {
    timestamps: false,
    product_id: {
        type: Sequelize.INTEGER, 
        primaryKey: true, 
        autoIncrement: true
    },
    product_name: Sequelize.STRING,
    product_description: Sequelize.TEXT,
    product_created: Sequelize.DATE,
    product_updated: Sequelize.DATE
}),

That would still automagically amend the product_created/product_updated columns on creates and updates. 这仍然会在创建和更新时自动修改product_created / product_updated列。

Another update strikes (and two years pass) and you can do just what you want : 另一次更新(并且两年过去了)你可以做你想做的事情:

products: sequelize.define('products', {
    timestamps: false,
    product_id: {
        type: Sequelize.INTEGER, 
        primaryKey: true, 
        autoIncrement: true
    },
    product_name: Sequelize.STRING,
    product_description: Sequelize.TEXT,
    product_created: Sequelize.DATE,
    product_updated: Sequelize.DATE
}, {
  updatedAt: 'product_updated',
  createdAt: 'product_created'
});

sadly this is not yet possible. 遗憾的是,这还不可能。 Can you please open an issue on github. 你能不能在github上打开一个问题。 I guess this is pretty easy to implement. 我想这很容易实现。

Thanks :) 谢谢 :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM