mirror of
https://github.com/jakejarvis/jarv.is.git
synced 2025-04-26 18:48:28 -04:00
29 lines
1.1 KiB
TypeScript
29 lines
1.1 KiB
TypeScript
import { PrismaClient } from "@prisma/client";
|
|
import { PrismaLibSQL } from "@prisma/adapter-libsql";
|
|
import { createClient } from "@libsql/client";
|
|
|
|
// creating PrismaClient here prevents next.js from starting too many concurrent prisma instances and exhausting the
|
|
// number of connection pools available (especially when hot reloading from `next dev`).
|
|
// https://www.prisma.io/docs/guides/other/troubleshooting-orm/help-articles/nextjs-prisma-client-dev-practices
|
|
|
|
const prismaClientSingleton = () => {
|
|
const libsql = createClient({
|
|
// TODO: use a local .db file for development. https://www.prisma.io/docs/orm/overview/databases/sqlite#connection-url
|
|
url: `${process.env.TURSO_DATABASE_URL}`,
|
|
authToken: `${process.env.TURSO_AUTH_TOKEN}`,
|
|
});
|
|
|
|
const adapter = new PrismaLibSQL(libsql);
|
|
|
|
return new PrismaClient({ adapter });
|
|
};
|
|
|
|
declare global {
|
|
// eslint-disable-next-line no-var
|
|
var prisma: undefined | ReturnType<typeof prismaClientSingleton>;
|
|
}
|
|
|
|
export const prisma = globalThis.prisma ?? prismaClientSingleton();
|
|
|
|
if (process.env.NODE_ENV !== "production") globalThis.prisma = prisma;
|