refactor(db): migrate app pages and APIs from Prisma facade to Drizzle (3)

Co-authored-by: Cursor <[email protected]>
This commit is contained in:
SimoandCursor committed 2026-08-01 14:15:32 +02:00
1 parent 2cd0863cb8
commit 580972c0a0
40 files changed
+1089 -808

No files matched your search

+20 -13
View File
@@ -1,7 +1,8 @@
import { desc, eq, inArray } from "drizzle-orm";
import { redirect } from "next/navigation";
import { AdminBreadcrumb } from "@/components/admin/admin-breadcrumb";
import { db, Items, ItemsBase, User } from "@/lib/db";
import { canAccess, getAdminContext, PERMS } from "@/lib/permissions";
import { prisma } from "@/lib/prisma";
import { loadRoom } from "../../_lib/load-room";
import { FurniClient } from "./furni-client";
@@ -18,10 +19,11 @@ export default async function RoomFurniPage({
const room = await loadRoom(id);
// Load items in this room. items.item_id → items_base.id
const items = await prisma.items.findMany({
where: { roomId: room.id },
orderBy: { id: "desc" },
});
const items = await db
.select()
.from(Items)
.where(eq(Items.roomId, room.id))
.orderBy(desc(Items.id));
// Resolve item bases
const baseIds = Array.from(
@@ -30,10 +32,15 @@ export default async function RoomFurniPage({
),
);
const bases = baseIds.length
? await prisma.itemsBase.findMany({
where: { id: { in: baseIds } },
select: { id: true, itemName: true, publicName: true, type: true },
})
? await db
.select({
id: ItemsBase.id,
itemName: ItemsBase.itemName,
publicName: ItemsBase.publicName,
type: ItemsBase.type,
})
.from(ItemsBase)
.where(inArray(ItemsBase.id, baseIds))
: [];
const baseMap = new Map(bases.map((b) => [b.id, b]));
@@ -42,10 +49,10 @@ export default async function RoomFurniPage({
new Set(items.map((i) => i.userId).filter((u) => u > 0)),
);
const users = userIds.length
? await prisma.user.findMany({
where: { id: { in: userIds } },
select: { id: true, username: true },
})
? await db
.select({ id: User.id, username: User.username })
.from(User)
.where(inArray(User.id, userIds))
: [];
const userMap = new Map(users.map((u) => [u.id, u.username]));
+18 -8
View File
@@ -1,21 +1,31 @@
import { eq } from "drizzle-orm";
import { notFound } from "next/navigation";
import { prisma } from "@/lib/prisma";
import { db, Rooms, User } from "@/lib/db";
export async function loadRoom(id: string) {
const roomId = parseInt(id, 10);
if (Number.isNaN(roomId)) notFound();
const room = await prisma.rooms.findUnique({
where: { id: roomId },
});
const [room] = await db
.select()
.from(Rooms)
.where(eq(Rooms.id, roomId))
.limit(1);
if (!room) notFound();
const owner =
room.ownerId > 0
? await prisma.user.findUnique({
where: { id: room.ownerId },
select: { id: true, username: true, look: true },
})
? ((
await db
.select({
id: User.id,
username: User.username,
look: User.look,
})
.from(User)
.where(eq(User.id, room.ownerId))
.limit(1)
)[0] ?? null)
: null;
return { ...room, owner };
}