Created
July 30, 2021 19:09
-
-
Save kentcdodds/9cac69a4091516d593fd126dc7f42579 to your computer and use it in GitHub Desktop.
Prisma is awesome. I love this!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async function getMostPopularPostSlugs({ | |
limit, | |
exclude, | |
}: { | |
limit: number | |
exclude: Array<string> | |
}) { | |
const result = await prisma.postRead.groupBy({ | |
by: ['postSlug'], | |
_count: true, | |
orderBy: { | |
_count: { | |
postSlug: 'desc', | |
}, | |
}, | |
where: { | |
postSlug: {notIn: exclude}, | |
}, | |
take: limit, | |
}) | |
return result.map(p => p.postSlug) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment