Download src/lib/db.ts from NAP1320/RotNot: direct link, hf CLI and curl.
- Browser
- Download file 954 Bytes
-
https://huggingface.co/spaces/NAP1320/RotNot/resolve/main/src/lib/db.ts
- Command line
-
hf download hf://spaces/NAP1320/RotNot/src/lib/db.ts
-
curl -L -o db.ts https://huggingface.co/spaces/NAP1320/RotNot/resolve/main/src/lib/db.ts
954 Bytes
| import { PrismaClient } from "@prisma/client"; | |
| import { PrismaLibSql } from "@prisma/adapter-libsql"; | |
| import path from "path"; | |
| const globalForPrisma = globalThis as unknown as { prisma: PrismaClient }; | |
| function createPrismaClient() { | |
| const dbUrl = | |
| process.env.DATABASE_URL ?? | |
| `file:${path.resolve(process.cwd(), "dev.db")}`; | |
| // A hosted libsql/Turso database (libsql://… or https://…) needs an auth | |
| // token. Local file: URLs ignore it. This lets the same code run locally on | |
| // SQLite and on a serverless host (e.g. Vercel) against a remote database. | |
| const authToken = | |
| process.env.TURSO_AUTH_TOKEN ?? process.env.DATABASE_AUTH_TOKEN; | |
| const adapter = new PrismaLibSql( | |
| authToken ? { url: dbUrl, authToken } : { url: dbUrl }, | |
| ); | |
| return new PrismaClient({ adapter }); | |
| } | |
| export const prisma = globalForPrisma.prisma || createPrismaClient(); | |
| if (process.env.NODE_ENV !== "production") globalForPrisma.prisma = prisma; | |