Skip to content

Instantly share code, notes, and snippets.

@tomfa
Created January 12, 2022 13:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomfa/a98cb09aaf519f82570e79bb5efe4c72 to your computer and use it in GitHub Desktop.
Save tomfa/a98cb09aaf519f82570e79bb5efe4c72 to your computer and use it in GitHub Desktop.
Connecting to multiple databases with Prisma
/*
* Source: https://github.com/prisma/prisma/issues/2443#issuecomment-630679118
* Client typings is generated with the cli commands below:
*
* prisma generate --schema prisma/schema1.prisma
* prisma generate --schema prisma/schema2.prisma
*/
import { PrismaClient as PrismaClient1 } from '../prisma/client1'
import { PrismaClient as PrismaClient2 } from '../prisma/client2'
const client1 = new PrismaClient1()
const client2 = new PrismaClient2()
datasource db {
provider = "postgres"
url = env("DB1_URL")
}
generator client {
provider = "prisma-client-js"
output = "./generated/client1"
}
model Model1 {
id Int @id @default(autoincrement())
model1Name String
}
datasource db {
provider = "postgres"
url = env("DB2_URL")
}
generator client {
provider = "prisma-client-js"
output = "./generated/client2"
}
model Model2 {
id Int @id @default(autoincrement())
model2Name String
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment