| 1234567891011121314151617181920212223242526272829303132 |
- import { PrismaClient, TranscodeStatus, ResolveStatus } from '@prisma/client';
- const globalForPrisma = globalThis as unknown as {
- prisma: PrismaClient | undefined;
- };
- export const prisma =
- globalForPrisma.prisma ??
- new PrismaClient({
- log: process.env.NODE_ENV === 'development' ? ['query', 'error', 'warn'] : ['error'],
- });
- // Re-export for convenience
- export { TranscodeStatus, ResolveStatus };
- // ── BigInt serialization helper ────────────────────────────────────────────────
- // Recursively converts all BigInt values in an object/array to Number.
- // Safe to pass through Prisma results before sending JSON responses.
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
- export function bigintToNumber(val: unknown): any {
- if (val === null || val === undefined) return val;
- if (typeof val === 'bigint') return Number(val);
- if (Array.isArray(val)) return val.map(bigintToNumber);
- if (typeof val === 'object') {
- const result: Record<string, unknown> = {};
- for (const [k, v] of Object.entries(val)) {
- result[k] = bigintToNumber(v);
- }
- return result;
- }
- return val;
- }
|