feat(don): stack top donate

This commit is contained in:
2026-06-10 22:03:39 +07:00 Unverified
parent ab676774ca
commit 056c94f56b
2 changed files with 9 additions and 6 deletions
+5 -3
View File
@@ -1,4 +1,5 @@
import { asc, desc, sql } from "drizzle-orm";
import type { SQL } from "drizzle-orm";
import { asc, desc, sql, sum } from "drizzle-orm";
import { Suspense } from "react";
import { Skeleton } from "@/components/ui/skeleton";
import { db } from "@/lib/db";
@@ -45,12 +46,13 @@ async function Content() {
i: sql<NumberLike>`ROW_NUMBER() OVER
(ORDER BY ${desc(donations.amount)}, ${asc(donations.id)})`,
name: donations.name,
amount: donations.amount,
amount: sum(donations.amount) as unknown as SQL<number>,
})
.from(donations)
.offset(3)
.limit(7)
.orderBy(desc(donations.amount), asc(donations.id));
.groupBy(donations.name)
.orderBy(desc(sum(donations.amount)), asc(donations.id));
const podium = await db
.select({
+4 -3
View File
@@ -2,16 +2,17 @@
import { db } from "@/lib/db";
import { donations } from "@/lib/db/schema";
import { asc, desc } from "drizzle-orm";
import { asc, desc, sum } from "drizzle-orm";
export async function getTopDonate() {
const [top] = await db
.select({
name: donations.name,
amount: donations.amount,
amount: sum(donations.amount),
})
.from(donations)
.limit(1)
.orderBy(desc(donations.amount), asc(donations.id));
.groupBy(donations.name)
.orderBy(desc(sum(donations.amount)), asc(donations.id));
return top;
}