简体   繁体   中英

Is there any way to convert the fields of raw Sequelize query into camelcase?

const sequelize = new Sequelize('db', 'userName', 'password',{
    dialect: 'postgres',
  define: {
    underscored: true,
    },
    query: {
        raw: true
    }
});

I am using underscored field values for the database and camelCase field values on application level. I am getting the data in correct format using sequelize querying methods but it is causing a problem when I use Raw Sequelize queries with sequelize.query() because it returns underscored field name. Is there any way to change this behavior?

  • It works.
class TheModel extends Sequelize.Model {

}

TheModel.init({
  userId: {type: DataTypes.INTEGER},
  label: {type: DataTypes.STRING},
}, {
  sequelize: sequelize,
  underscored: true,
}

...

TheModel.rawAttributes['userId'].field    // 'user_id'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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