prisma.ts 1.2 KB

1234567891011121314151617181920212223242526272829303132
  1. import { PrismaClient, TranscodeStatus, ResolveStatus } from '@prisma/client';
  2. const globalForPrisma = globalThis as unknown as {
  3. prisma: PrismaClient | undefined;
  4. };
  5. export const prisma =
  6. globalForPrisma.prisma ??
  7. new PrismaClient({
  8. log: process.env.NODE_ENV === 'development' ? ['query', 'error', 'warn'] : ['error'],
  9. });
  10. // Re-export for convenience
  11. export { TranscodeStatus, ResolveStatus };
  12. // ── BigInt serialization helper ────────────────────────────────────────────────
  13. // Recursively converts all BigInt values in an object/array to Number.
  14. // Safe to pass through Prisma results before sending JSON responses.
  15. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  16. export function bigintToNumber(val: unknown): any {
  17. if (val === null || val === undefined) return val;
  18. if (typeof val === 'bigint') return Number(val);
  19. if (Array.isArray(val)) return val.map(bigintToNumber);
  20. if (typeof val === 'object') {
  21. const result: Record<string, unknown> = {};
  22. for (const [k, v] of Object.entries(val)) {
  23. result[k] = bigintToNumber(v);
  24. }
  25. return result;
  26. }
  27. return val;
  28. }