prisma neon adapter

hey, is that the right way to implement the prisma neon adapter?
import { PrismaClient } from "@prisma/client";
import { PrismaNeon } from "@prisma/adapter-neon";
import { Pool } from "@neondatabase/serverless";

declare global {
var prisma: PrismaClient | undefined;
}

const connectionString = `${process.env.DATABASE_URL}`;

const pool = new Pool({ connectionString })
const adapter = new PrismaNeon(pool);

export const db = globalThis.prisma || new PrismaClient({ adapter });

if (process.env.NODE_ENV !== "production") globalThis.prisma = db;
import { PrismaClient } from "@prisma/client";
import { PrismaNeon } from "@prisma/adapter-neon";
import { Pool } from "@neondatabase/serverless";

declare global {
var prisma: PrismaClient | undefined;
}

const connectionString = `${process.env.DATABASE_URL}`;

const pool = new Pool({ connectionString })
const adapter = new PrismaNeon(pool);

export const db = globalThis.prisma || new PrismaClient({ adapter });

if (process.env.NODE_ENV !== "production") globalThis.prisma = db;
7 Replies
Poggerssss
PoggerssssOP2mo ago
okay, actually I'll get this error on viewing the page now: https://just-paste.it/Rf1444SR8r
Nurul
Nurul2mo ago
Hey @Poggerssss Can you provide a minimal reproduction for this error so that we can investigate? Is your repository open source?
Poggerssss
PoggerssssOP2mo ago
hey, sadly, my project isn't open source and its a already almost finished project, so providing a similar reproduction would be not easy. could I add you manually to the repository? The first time, I already used the how to. Just tried it again and I am still getting this error, after my Middleware is compiled & I visit the page. https://just-paste.it/0b9zkod1F8 okay, I just tried to add "native" to the binaryTarget for local development. Now the Next-Server isn't crashing anymore, but I'll get this error: https://just-paste.it/24oc0kfi49 I got it now. but if I deploy this to my kubernetes cluster, the app isn't able to connect to the database anymore. What could I do about this? "Can't reach database server at ..." hey @Nurul (Prisma) I still can't connect to the database in the kubernetes cluster - what could I do? in local development, its working fine...
Nurul
Nurul2mo ago
If I understand correctly, your database is reachable via local environment, but not from your kubernetes cluster? You get the error: Can't reach database server at ..., right? I don't think this error is related to neon adapter. Do you have any VPN of any sorts that might be preventing database connection?
Poggerssss
PoggerssssOP2mo ago
no, nothing about that. could it be because of the Middleware? I am using authjs and have read, that Prisma dont support the middleware..
Nurul
Nurul2mo ago
Middlewares are now deprecated in favour of client extensions, though I don't think using middleware could cause this error. If you comment out the middleware, are you able to connect to the database?
Want results from more Discord servers?
Add your server