refactor(db): migrate app pages and APIs from Prisma facade to Drizzle (2)
Co-authored-by: Cursor <[email protected]>
This commit is contained in:
1 parent
7c39aef5d9
commit
2cd0863cb8
40 files changed
+1069
-726
No files matched your search
@@ -1,8 +1,9 @@
|
||||
import { eq } from "drizzle-orm";
|
||||
import type { Metadata } from "next";
|
||||
import Link from "next/link";
|
||||
import { notFound } from "next/navigation";
|
||||
import { ContentCard, EmptyState, StatBlock } from "@/components/public/ui";
|
||||
import { prisma } from "@/lib/prisma";
|
||||
import { db, Rooms, User } from "@/lib/db";
|
||||
|
||||
export const revalidate = 300;
|
||||
|
||||
@@ -31,24 +32,25 @@ function parseRoomId(raw: string): number | null {
|
||||
async function getRoom(raw: string) {
|
||||
const id = parseRoomId(raw);
|
||||
if (id === null) return null;
|
||||
return prisma.rooms
|
||||
.findUnique({
|
||||
where: { id },
|
||||
select: {
|
||||
id: true,
|
||||
ownerId: true,
|
||||
ownerName: true,
|
||||
name: true,
|
||||
description: true,
|
||||
state: true,
|
||||
users: true,
|
||||
usersMax: true,
|
||||
category: true,
|
||||
score: true,
|
||||
tags: true,
|
||||
},
|
||||
const [room] = await db
|
||||
.select({
|
||||
id: Rooms.id,
|
||||
ownerId: Rooms.ownerId,
|
||||
ownerName: Rooms.ownerName,
|
||||
name: Rooms.name,
|
||||
description: Rooms.description,
|
||||
state: Rooms.state,
|
||||
users: Rooms.users,
|
||||
usersMax: Rooms.usersMax,
|
||||
category: Rooms.category,
|
||||
score: Rooms.score,
|
||||
tags: Rooms.tags,
|
||||
})
|
||||
.catch(() => null);
|
||||
.from(Rooms)
|
||||
.where(eq(Rooms.id, id))
|
||||
.limit(1)
|
||||
.catch(() => []);
|
||||
return room ?? null;
|
||||
}
|
||||
|
||||
export async function generateMetadata({
|
||||
@@ -83,12 +85,14 @@ export default async function RoomPage({
|
||||
// owner_name column if the account row is missing or the query degrades.
|
||||
const owner =
|
||||
room.ownerId > 0
|
||||
? await prisma.user
|
||||
.findUnique({
|
||||
where: { id: room.ownerId },
|
||||
select: { username: true },
|
||||
})
|
||||
.catch(() => null)
|
||||
? (
|
||||
await db
|
||||
.select({ username: User.username })
|
||||
.from(User)
|
||||
.where(eq(User.id, room.ownerId))
|
||||
.limit(1)
|
||||
.catch(() => [])
|
||||
)[0]
|
||||
: null;
|
||||
const ownerName = owner?.username || room.ownerName || "Unknown";
|
||||
|
||||
|
||||
Reference in new issue
Block a user