Reputation: 75
I am trying to create QueryBuilder query but all the time failing. I need to write query like this:
SELECT userId, COUNT(*) votes from uservotes WHERE sessionId = ? GROUP BY userId
but using QueryBuilder All that I done and somehow work it is this variant.
.createQueryBuilder('uservotes')
.select([
'uservotes.userId', 'userId',
])
.where({ sessionId: sessionId })
.groupBy('userId')
.getMany();
Will be very grateful for help
Upvotes: 1
Views: 90
Reputation: 1282
You can use like this
const countByUserVotes = await Uservotes.createQueryBuilder()
.select(['userId', 'count(*) as count'])
.where({ sessionId: sessionId })
.groupBy('userId')
.getRawMany();
Upvotes: 2