Я определяю модель Sequelize для сопоставления полей из существующих таблиц в моей базе данных.Однако имена полей в таблице длинные и не удобны для разработчиков.
Можно ли сопоставить имена полей базы данных с псевдонимами в определении модели, чтобы у моей службы было более удобных для разработчиков имен свойств модели для работы?
Пример:
Это ...
// Horrible field names
module.exports = (sequelize, DataTypes) =>
sequelize.define('Transaction', {
f_curr_finaccount__amount: DataTypes.DECIMAL,
f_curr_finaccount__tx_type: DataTypes.STRING,
f_finaccount__currency_iso_id: DataTypes.STRING,
f_lex_finaccount__tx_atomic_status: DataTypes.STRING
}, {
schema: 'fins',
tableName: 'fins_financialaccounttransaction',
timestamps: false
})
... становится ...
// Developer-friendly field names
module.exports = (sequelize, DataTypes) =>
sequelize.define('Transaction', {
amount: {
type: DataTypes.DECIMAL,
fieldName: 'f_curr_finaccount__amount'
},
type: {
type: DataTypes.STRING,
fieldName: 'f_curr_finaccount__tx_type'
},
currency: {
type: DataTypes.STRING,
fieldName: 'f_finaccount__currency_iso_id'
},
status: {
type: DataTypes.STRING,
fieldName: 'f_lex_finaccount__tx_atomic_status'
}
}, {
schema: 'fins',
tableName: 'fins_financialaccounttransaction',
timestamps: false
})