Created
May 17, 2024 21:39
-
-
Save PaulieScanlon/f102ec0e6c23b97bfde6a244f01cdadb to your computer and use it in GitHub Desktop.
Happy Reactions Production Drizzle ORM query
This file contains 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
.select({ | |
city: analytics.city, | |
country: analytics.country, | |
flag: analytics.flag, | |
count: sql`COUNT(${reactions.id})`.as('count'), | |
}) | |
.from(analytics) | |
.innerJoin(reactions, eq(analytics.slug, reactions.slug)) | |
.where(and(eq(reactions.reaction, 'happy'), gte(analytics.date, new Date(new Date().getTime() - 30 * 24 * 60 * 60 * 1000)))) | |
.groupBy(analytics.city, analytics.country, analytics.flag) | |
.orderBy(desc(sql`count`)) | |
.limit(50); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment