completed paginated Component

This commit is contained in:
PxlLoewe
2025-02-07 00:15:11 +01:00
parent be5128053f
commit 42023f9bb2
4 changed files with 102 additions and 17 deletions

View File

@@ -0,0 +1,24 @@
'use server';
import { PrismaClient } from '@repo/db';
export const getData = async (
prismaModelName: keyof PrismaClient,
take: number,
skip: number
) => {
const prisma = new PrismaClient();
if (
!prismaModelName ||
!prisma[prismaModelName] ||
!('findMany' in prisma[prismaModelName])
)
return;
const model = prisma[prismaModelName] as any;
if (!model.findMany || !model.count) return;
const data = await model.findMany({
take,
skip,
});
const total = await model.count();
return { data, total };
};