P
Prisma2mo ago
sommeeeR

Multiple data sources

So I get my db which is a PrismaClient with this piece of code. We also have 2 databases which is up all the time and synced. Are there any way to use multiple database urls so if one fails it will go to the next one?
export const db =
globalForPrisma.prisma ??
new PrismaClient({
log: process.env.NODE_ENV === 'development' ? ['error'] : ['error'],
// Anyway to use multiple URLs here if one of them is failing
datasourceUrl: process.env.DATABASE_URL,
});

if (process.env.NODE_ENV !== 'production') globalForPrisma.prisma = db;
export const db =
globalForPrisma.prisma ??
new PrismaClient({
log: process.env.NODE_ENV === 'development' ? ['error'] : ['error'],
// Anyway to use multiple URLs here if one of them is failing
datasourceUrl: process.env.DATABASE_URL,
});

if (process.env.NODE_ENV !== 'production') globalForPrisma.prisma = db;
2 Replies
Prisma AI Help
Prisma AI Help2mo ago
Howdy, friend! I'm the Prisma AI Help Bot — fast answers from me, or slow, hand-crafted wisdom from a dev? Choose wisely, adventurer.
Ankur Datta
Ankur Datta2mo ago
You can try using the read replica extension for this 👇🏾 https://www.prisma.io/docs/orm/prisma-client/setup-and-configuration/read-replicas
Read replicas | Prisma Documentation
Learn how to set up and use read replicas with Prisma Client

Did you find this page helpful?