IssueRaiser

Multiple Connections / Databases / Datasources

## Problem An application may need to access different connections/databases. One use case could be having the exact same set of tables into different databases (multi-tenant approach). Another use case could be having to access punctually some specific data in a separate database/server. In any cases "a single connection" for the entire application is a really **strong** limitation. Any SQL driver or ORM is capable of connecting to multiple databases either by direct support (TypeOrm) or by creating 2 instances. Unless I missed something this is not possible with Prisma client. ## Suggested solution I believe that it can be easily achieved with the following approach that does not change much both on the schema and client side of things. ```prisma datasource proj01 { provider = "postgresql" url = env("DATABASE_URL_PROJ01") models = [Post, User] } datasource proj02 { provider = "postgresql" url = env("DATABASE_URL_PROJ02") models = [Post, User] } datasource common { provider = "postgresql" url = env("DATABASE_URL_COMMON") models = [Config] } generator client { provider = "prisma-client-js" } model Post { id Int @id @default(autoincrement()) title String content String? published Boolean @default(false) author User? @relation(fields: [authorId], references: [id]) authorId Int? } model User { id Int @id @default(autoincrement()) email String @unique name String? posts Post[] } model

Posted by FredericLatour on May 14, 2020, 12:21 PM

Tags

Related issues

Raise real-world problems, find people facing the same issue, and discuss solutions.3,500 issues0 comments

support (Sysadmin)

Multiple Connections / Databases / Datasources

FredericLatourMay 14, 2020, 12:21 PM

## Problem An application may need to access different connections/databases. One use case could be having the exact same set of tables into different databases (multi-tenant approach). Another use case could be having to access punctually some specific data in a separate database/server. In any cases "a single connection" for the entire application is a really **strong** limitation. Any SQL driver or ORM is capable of connecting to multiple databases either by direct support (TypeOrm) or by creating 2 instances. Unless I missed something this is not possible with Prisma client. ## Suggested solution I believe that it can be easily achieved with the following approach that does not change much both on the schema and client side of things. ```prisma datasource proj01 { provider = "postgresql" url = env("DATABASE_URL_PROJ01") models = [Post, User] } datasource proj02 { provider = "postgresql" url = env("DATABASE_URL_PROJ02") models = [Post, User] } datasource common { provider = "postgresql" url = env("DATABASE_URL_COMMON") models = [Config] } generator client { provider = "prisma-client-js" } model Post { id Int @id @default(autoincrement()) title String content String? published Boolean @default(false) author User? @relation(fields: [authorId], references: [id]) authorId Int? } model User { id Int @id @default(autoincrement()) email String @unique name String? posts Post[] } model

Comments (0)

No comments yet. Start the discussion.

Comment on this issue