zach.codes

zach.codes

Share this post

zach.codes
zach.codes
Multiple Prisma Clients, One App
Copy link
Facebook
Email
Notes
More

Multiple Prisma Clients, One App

Zach Silveira
Nov 24, 2021
∙ Paid

Share this post

zach.codes
zach.codes
Multiple Prisma Clients, One App
Copy link
Facebook
Email
Notes
More
Share
Multiple Prisma Clients, One App

There are times where you need to connect to multiple databases within a single backend server. I've found this is a lightly documented subject on the official Prisma docs, and wanted to make a quick guide for others.

I have been working on a GraphQL server that combines multiple internal datasets from our company, so it's crucial that I can easily query all of these different Postgres databases.

Initial Setup

In the top level of your app (where the package.json is located) install prisma like normal:

yarn add prisma @prisma/client

Next, create a new folder for every database you need to access. For example purposes we will make a folder called db1 and db2

In each folder, run the following:

npx prisma init

Next, open the prisma/schema.prisma file, and make one change:

generator client {
  provider = "prisma-client-js"
  output   = "../../src/generated/db1"
}

We are telling it to output the client into our src folder at the root of the project, inside of a generated folder. You should add this f…

Keep reading with a 7-day free trial

Subscribe to zach.codes to keep reading this post and get 7 days of free access to the full post archives.

Already a paid subscriber? Sign in
© 2025 Zach Silveira
Privacy ∙ Terms ∙ Collection notice
Start writingGet the app
Substack is the home for great culture

Share

Copy link
Facebook
Email
Notes
More