gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 22:39:09 25 4
gpt4 key购买 nike

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

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com