node.js - Sequelize 将所有表字段更改为蛇形大小写

标签 node.js sequelize.js

我正在尝试进行迁移以将所有现有的表字段更改为蛇形大小写,并且将来已经以这种方式编写。
到目前为止,我一直在这样做

myTableField = {type: datatype.stmh, field: 'my_table_field'}

事情是我想停止这样做,对于 future 的领域,我只需要直接使用蛇盒设置它们。

有没有办法做到这一点?或者我必须为每个手动运行一个更改字段?

最佳答案

通过下划线模型选项,可以不将模型定义中的每个字段重命名为下划线。

options.underscored - Converts all camelCased columns to underscored if true
options.underscoredAll - Converts camelCased model names to underscored table names if true

前任:
const User = sequelize.define('User', {
               firstname: Sequelize.STRING,
               lastname: Sequelize.STRING
             },{ 
                underscored:true})

同样在 CLI 上,我们可以选择使用 snakecase 生成迁移
>> sequelize model:generate --name User --attributes firstName:string,lastName:string  --underscored 

在哪里
 --underscored      Use snake case for the timestamp's attribute names    

但它仅适用于迁移定义上的时间戳字段。

关于node.js - Sequelize 将所有表字段更改为蛇形大小写,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53104609/

相关文章:

node.js - Sequelize Many-to-Many Association -- "Include"查询错误说没有关联

node.js - 使用sequelize序列化外键的JSON数组

javascript - 如何编辑带有文本的内联按钮? Telegram Bot 、 Telegram 、 Node

javascript - 如何创建一个 sequelize 事务来保存深度嵌套的对象

sequelize.js - 如何在 Sequelize 中将关联设置为可空

javascript - 在使用 Cloud Functions 时,如何使用 Firebase Admin SDK 更改 Firebase 实时数据库中的数据?

javascript - Sequelize : Connect multiple databases with the same schema

java - 使用不同语言的最佳实践是什么?

node.js - 为 npm 注册表 URL 设置用户名和密码

javascript - Node.js:http.Server、http.Agent、sockets、http.request的关系