I'm using PostgreSQL. I have a reading value in my table. From that, I have to find the consumption by subtracting previous value.
I found the SQL query. How to use that in sequelize? Is there any other option except raw queries?
SQL Query:
SELECT "readingValue",
"readingValue" - COALESCE(LAG("readingValue") OVER
(ORDER BY "readingTime")) AS consumption
FROM public."tableName" LIMIT 100;
You can do that with sequelize literal.
model.update({'count': sequelize.literal('count + 1')}, { where: { id: 1 }})
You can also do it with increment method.
Model.increment('seq', { by: 5, where: { id: 'model_id' });
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