Skip to content

Instantly share code, notes, and snippets.

@PaulieScanlon
Created May 17, 2024 21:39
Show Gist options
  • Save PaulieScanlon/f102ec0e6c23b97bfde6a244f01cdadb to your computer and use it in GitHub Desktop.
Save PaulieScanlon/f102ec0e6c23b97bfde6a244f01cdadb to your computer and use it in GitHub Desktop.
Happy Reactions Production Drizzle ORM query
.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