開発体験(developer experience) DB query in API routes or RCS
将来ちゃんとしたAPIのエンドポイントを作るか迷っていたため、RSCにてDBクエリを書く方法で行くか迷っていたためNext.js API routesに書いていたんですがtypeのinferしてくれなくて使いづらいかった。 まずはこんな感じで api routes export async function GET( request: NextRequest, { params }: { params: Promise<{ id: string }> } ) { try { const { id } = await params; const spot = await db.query.napSpots.findFirst({ where: eq(napSpots.id, id), with: { ratings: { with: { user: true, }, }, }, }); if (!spot) { console.error("[API] Nap spot not found for ID:", id); return NextResponse.json( { error: "Nap spot not found" }, { status: 404 } ); } return NextResponse....