node.js - Sequelize : camelCase attribute names in but snake_case in posrgres?

标签 node.js sequelize.js

var Project = sequelize.define('project', {
  someAttribute: {type: Sequelize.STRING, primaryKey: true },
}, {
  'freezeTableName': true
});

这是一个现有数据库,其中列名称以蛇形命名法 some_attribute 命名。然而,由于它是一个nodejs代码库,我想使用camelCase someAttribute

Sequelize 可以实现这一点吗?

最佳答案

我知道这个问题有点老了,只是为 future 的 Google 用户发布这个答案。

您可以使用 field 属性覆盖列名称。

http://sequelize.readthedocs.org/en/latest/docs/models/

var Foo = sequelize.define('Foo', {
 // You can specify a custom field name via the "field" attribute:
 fieldWithUnderscores: { type: Sequelize.STRING, field: "field_with_underscores" }
})

关于node.js - Sequelize : camelCase attribute names in but snake_case in posrgres?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24482650/

相关文章:

node.js - 我应该如何批量上传到 s3 并通过最终回调从 nodeJS 网络服务器插入到 MongoDB?

javascript - node.js 找不到模块 './lib/compat'

javascript - 尝试在数组内映射数组并显示在表格中

javascript - Sequelize 数据库错误: Cannot truncate a table referenced in a foreign key constraint

javascript - Node JS : Preview downloading images*

node.js - faye-websocket-node 作为客户端和 sockjs-node 作为服务器的问题

javascript - 需要统计一个连接表的行数 sequelize

javascript - Sequelize update with association 不更新关联模型的表

sequelize.js - 创建行但 promise 不解决

node.js - 预期未在 supertest-as-promised 中定义