PrismaP
Prisma2y ago
15 replies
Hinky

too many db connections on Prisma Accelerate

Hello!
hope you are all well.

I am using prisma accelerate to avoid this issue, but funny enough im running into it now im using accelerate (wasnt before i switch to prisma accelerate, (all just dev, not production yet))

I attached image of the error im running into. I for sure have prisma accelerate connected correctly, today i did like 30k queries.

So my initial thought is the prisma singleton i have in my monorepo isnt working with hot reloading, but i still assumed should be okay because shouldnt be connecting directly, unless i do prisma migrate or similar, but i havent used that today.

This is my current prisma singleton, but remember its in monorepo (turbo), idk if that changes anything.
import { PrismaClient } from "@prisma/client/edge";
// norm imports
import { withAccelerate } from "@prisma/extension-accelerate";

// refers to this
// https://github.com/prisma/accelerate-nextjs-starter/blob/main/lib/db.ts
//
const prismaClientSingleton = () => {
    return new PrismaClient({
        log:
            // process.env.NODE_ENV === "development"
            // ? ["query", "error", "warn"]
            // : ["error"],
            process.env.NODE_ENV === "development"
                ? ["error", "warn"]
                : ["error"],
        // process.env.NODE_ENV === "development" ? ["error"] : ["error"],
    }).$extends(withAccelerate());
};

type tPrismaClientSingleton = ReturnType<typeof prismaClientSingleton>;

const globalForPrisma = globalThis as unknown as {
    prisma: tPrismaClientSingleton | undefined;
};

export const prisma = globalForPrisma.prisma ?? prismaClientSingleton();

if (process.env.NODE_ENV !== "production") globalForPrisma.prisma = prisma;



any help would be awesome, thank you! also if anyone is from philippines, id love some dev help on fulltime basis (just chucking that out there too)
image.png
Was this page helpful?