sequelize-auto:程序化API选项中的Camel案例

时间:2017-08-04 15:57:08

标签: mysql node.js sequelize.js

如何使用Programmatic API选项在sequelize-auto中获取camelCase列名?我已经尝试过这样:

const options = {
  host: 'localhost',
  dialect: 'mysql',
  directory: './models',
  port: '3306',
  logging: false,
  additional: {
      camel: true,
      timestamps: false
  }
}

const options = {
  host: 'localhost',
  dialect: 'mysql',
  directory: './models',
  port: '3306',
  logging: false,
  camel: true,
  additional: {
      timestamps: false
  }
}

但这似乎都不起作用,我做错了什么?

最诚挚的问候。

2 个答案:

答案 0 :(得分:1)

基于https://github.com/sequelize/sequelize-auto/blob/master/lib/index.js看起来你很近!您只需将camel选项重命名为camelCase即可......

const options = {
  host: 'localhost',
  dialect: 'mysql',
  directory: './models',
  port: '3306',
  logging: false,
  camelCase: true, // <-- Do this!
  additional: {
      timestamps: false
  }
}
祝你好运! :)

答案 1 :(得分:0)

还有一个camelCaseForFileName选项。在命令行上是-f或--camelCaseForFileName,在编程上,我使用了此代码:

var SequelizeAuto = require('sequelize-auto-v3')
var auto = new SequelizeAuto('money', 'root', '',{
    host: 'localhost',
    dialect: 'mysql',
    output: './models',
    camelCase: true,
    camelCaseForFileName: true,
    // account_access_rules vs accountAccessRules:
    additional: {
        timestamps: false,
        underscored: false
    }
});

auto.run(function (err) {
...}

这会将在models文件夹(例如,表account_access_rules)中生成的文件名从account_access_rules.js更改为accountAccessRules.js

很抱歉将此问题作为答案(因为该问题仅询问列名,并且此答案重复了有关列名的答案,并添加了有关文件名的信息),但我无法在注释中显示工作代码。