I am new to sequelize. I am not sure how to convert this MySql query so that I can use it in my node.js file.
MySql query:
SELECT Rtrim(Ltrim(childstatus)),TIMESTAMPDIFF(d,dob,now(3))
INTO @childstatus, @Ageday
FROM childdetails where registno=@registno
I have sequelize model for childdetails. I am not sure how to structure this query.
CodePudding user response:
You can use Sequelize.fn
to call these two functions indicating them in attributes
option like this:
const details = await ChildDetials,.findAll({
attributes: [
[Sequelize.fn('RTrim', Sequelize.fn('LTrim', Sequelize.col('childstatus'))), 'childsttaus'],
[Sequelize.fn('TIMESTAMPDIFF', Sequelize.literal('d'), Sequelize.col('dob'), Sequelize.fn('now', 3)), 'Ageday']
],
where: {
registno: registno
}
})