Skip to content

Tag: sequelize.js

Sequelize query. Multiple count depends on column name

I have working query: It returns total count for all columns that has code=1081 and 1082 in “Region” table. In “Region” table there is “code” row that has 5 different codes. It’s a primary key to GeograpicalAdministrativeAreas table. I need to calculate for each column separated amount (not only for 1081 and 1082 in total how it is now). So

How to use group by in sql? (I need sequelize)

I have But it fails with this error: Works fine without GROUP BY Answer The GROUP BY statement groups rows that have the same values into summary rows, in your case, it is the country_code. It is often used with aggregate functions (COUNT(), MAX(), MIN(), SUM(), AVG()) to group the result-set by one or more columns. That means, for expl

Converting a SQL query to SEQUELIZE

I am trying to wrap my head around creating this sequelize query. I have been able to create 2 separate queries where the ‘order by filter’ works and ‘aliases’ work, but not combined. This is what i currenty have in sequelize Answer You just need to use fn twice: in order and in attributes options: Also you can combine findAll

Sequelize : How to query posts list from user id list?

To learn a little bit how a back end application works i’m currently creating a small instagram-like app using nodejs and sequelize (reactjs for the front). I have 3 SQL tables : Users id (pk) username email password Posts id (pk) userId (fk) message mediaUrl Following id (pk) userId (fk) followingId (fk) I would like to know what is the

Nest Postgresql Sequelize one-to-one Error with ForeignKey

My Table Has one-to-one connection with table But when i try add some data in second table< i got an Error – Nest error insert or update on table “checkingResults” violates foreign key constraint “checkingResults_resultId_fkey” What happened? I try any thing… And how i remember – a don’t get this error before in this place, i don’t touch something in

How can I convert SQL-query to Sequelize?

I have this SQL query: It returns the last message in the given chat. But I don’t understand at all how to execute this moment IN (SELECT MAX( FROM messages GROUP BY messages.chatId)) AS lastMessage ON = lastMessage.chatId in Sequelize… Answer You can use Sequelize.literal like this: