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)
Support connecting to remote devcontainers (devcontainer on remote host)
Option to use Waffle menu or links displayed normally
I also attempted to package ROCM on musl.
But why is there no such pushback agains linux kernel?
OpenCode Support
Upcoming changes to the tado° API
Allow Mac users to use Apple native containerization
Support for the Containerization Framework on macOS
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
Comments (0)
No comments yet. Start the discussion.