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

Co-authored-by: Cursor <[email protected]>
This commit is contained in:
SimoandCursor committed 2026-08-01 14:15:39 +02:00
1 parent 9aa4f331bf
commit 30b54e99e7
40 files changed
+1183 -784

No files matched your search

+18 -16
View File
@@ -1,32 +1,34 @@
import { count, desc } from "drizzle-orm";
import { apiJson, pagination } from "@/lib/api";
import { prisma } from "@/lib/prisma";
import { CameraWeb, db } from "@/lib/db";
export const dynamic = "force-dynamic";
/**
* GET /api/photos — recent community photos (camera_web), newest first.
* Mirrors the /photos page query (prisma.cameraWeb). Returns id, userId, url
* and timestamp plus pagination metadata.
* Mirrors the /photos page query. Returns id, userId, url and timestamp plus
* pagination metadata.
*/
export async function GET(req: Request) {
const sp = new URL(req.url).searchParams;
const { page, perPage, skip, take } = pagination(sp);
try {
const [total, photos] = await Promise.all([
prisma.cameraWeb.count(),
prisma.cameraWeb.findMany({
select: {
id: true,
userId: true,
url: true,
timestamp: true,
},
orderBy: { timestamp: "desc" },
skip,
take,
}),
const [totalRows, photos] = await Promise.all([
db.select({ total: count() }).from(CameraWeb),
db
.select({
id: CameraWeb.id,
userId: CameraWeb.userId,
url: CameraWeb.url,
timestamp: CameraWeb.timestamp,
})
.from(CameraWeb)
.orderBy(desc(CameraWeb.timestamp))
.limit(take)
.offset(skip),
]);
const total = totalRows[0]?.total ?? 0;
return apiJson({
data: photos,