I would know how can I write some query using FLOAT value with sequelize ?
I tried that :
const Stat = sequelize.define('stat', {
ID : { type: DataTypes.INTEGER, allowNull: false },
displayName: { type: DataTypes.STRING, allowNull: false },
shortName : { type: DataTypes.STRING, allowNull: false },
value : { type: DataTypes.FLOAT(10, 1), allowNull: false }
},
{
freezeTableName: true,
timestamps: false
})
//-------------
const test = await Stat.findOne({
where: {
shortName: shortName,
value : 22.1
},
attributes: ['displayName', 'shortName', 'value']
})
but it writes :
SELECT `displayName`, `shortName`, `value` FROM `stat` AS `stat` WHERE `stat`.`shortName` = 'TC' AND `stat`.`value` = '22.1' LIMIT 1;
with SQL '22.1'
=/= 22.1
then with this generated query, I can't fetch any rows.
Typically, I just want a way to have that instead :
SELECT `displayName`, `shortName`, `value` FROM `stat` AS `stat` WHERE `stat`.`shortName` = 'TC' AND `stat`.`value` = 22.1 LIMIT 1;
Thanks in advance to everyone who will help me !
EDIT I found this solutions that works well actually, but yeah- It's not that good... May I ask about opinions ?
const test = await Stat.findOne({
attributes: ['displayName', 'shortName', 'value'],
where: {
shortName: shortName,
value: sequelize.literal(`value = ${value}`)
}
})