refactor(db): migrate app pages and APIs from Prisma facade to Drizzle (3)
Co-authored-by: Cursor <[email protected]>
This commit is contained in:
1 parent
2cd0863cb8
commit
580972c0a0
40 files changed
+1089
-808
No files matched your search
@@ -1,6 +1,7 @@
|
||||
import { asc, count, gt } from "drizzle-orm";
|
||||
import { redirect } from "next/navigation";
|
||||
import { CatalogItems, db, Soundtracks } from "@/lib/db";
|
||||
import { canAccess, getAdminContext, PERMS } from "@/lib/permissions";
|
||||
import { prisma } from "@/lib/prisma";
|
||||
import { siteSettings } from "@/lib/services/site-settings";
|
||||
import {
|
||||
DEFAULT_SOUNDTRACK_BASE_URL,
|
||||
@@ -18,28 +19,31 @@ export default async function SoundsPage() {
|
||||
const canEdit = canAccess(permissions, PERMS.CATALOG_EDIT, session.user.rank);
|
||||
|
||||
const [rows, usage, baseUrlSetting] = await Promise.all([
|
||||
prisma.soundtracks.findMany({
|
||||
orderBy: { id: "asc" },
|
||||
select: {
|
||||
id: true,
|
||||
code: true,
|
||||
name: true,
|
||||
author: true,
|
||||
length: true,
|
||||
track: true,
|
||||
},
|
||||
}),
|
||||
prisma.catalogItems.groupBy({
|
||||
by: ["songId"],
|
||||
where: { songId: { gt: 0 } },
|
||||
_count: { _all: true },
|
||||
}),
|
||||
db
|
||||
.select({
|
||||
id: Soundtracks.id,
|
||||
code: Soundtracks.code,
|
||||
name: Soundtracks.name,
|
||||
author: Soundtracks.author,
|
||||
length: Soundtracks.length,
|
||||
track: Soundtracks.track,
|
||||
})
|
||||
.from(Soundtracks)
|
||||
.orderBy(asc(Soundtracks.id)),
|
||||
db
|
||||
.select({
|
||||
songId: CatalogItems.songId,
|
||||
total: count(),
|
||||
})
|
||||
.from(CatalogItems)
|
||||
.where(gt(CatalogItems.songId, 0))
|
||||
.groupBy(CatalogItems.songId),
|
||||
siteSettings.get("soundtrack_base_url", DEFAULT_SOUNDTRACK_BASE_URL),
|
||||
]);
|
||||
|
||||
const usageMap: Record<number, number> = {};
|
||||
for (const row of usage) {
|
||||
if (row.songId != null) usageMap[row.songId] = row._count._all;
|
||||
if (row.songId != null) usageMap[row.songId] = Number(row.total);
|
||||
}
|
||||
|
||||
const soundtracks = rows.map((r) => {
|
||||
|
||||
Reference in new issue
Block a user