I'm trying to implement this SQL to my Sequelize
SELECT file_id FROM table WHERE datediff(curdate(),create_date) > 5;
Here is my Sequelize
findOverPeriodFile: function () {
return table.findAll({
where:{
60: {lt: Sequelize.fn('')}
}
});
}
Im new to Seuelize and I have tried to search Google, but it doesn't help. Does anyone have an answer to this question? I don't know what to put in the WHERE
statement. Sorry for my bad English.
Here you go :
You can generate WHERE datediff(curdate(),create_date) > 5;
by using :
{
where: sequelize.where(sequelize.fn('datediff', sequelize.fn("NOW") , sequelize.col('create_date')), {
$gt : 5 // OR [Op.gt] : 5
})
}
For adding more condition
{
where: {
$and : [
sequelize.where(sequelize.fn('datediff', sequelize.fn("NOW") , sequelize.col('create_date')), {
$gt : 5 // OR [Op.gt] : 5
}) ,
{ status : 'mystatus' }
]
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With