{"id":19683920,"url":"https://github.com/prisma/prisma-read-replica-middleware","last_synced_at":"2026-02-17T13:32:15.395Z","repository":{"id":66108823,"uuid":"463686117","full_name":"prisma/prisma-read-replica-middleware","owner":"prisma","description":null,"archived":false,"fork":false,"pushed_at":"2022-08-26T09:07:46.000Z","size":337,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":20,"default_branch":"main","last_synced_at":"2026-02-02T21:52:11.329Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/prisma.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2022-02-25T21:56:29.000Z","updated_at":"2024-01-04T22:08:42.000Z","dependencies_parsed_at":"2023-02-26T06:30:29.578Z","dependency_job_id":null,"html_url":"https://github.com/prisma/prisma-read-replica-middleware","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/prisma/prisma-read-replica-middleware","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/prisma%2Fprisma-read-replica-middleware","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/prisma%2Fprisma-read-replica-middleware/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/prisma%2Fprisma-read-replica-middleware/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/prisma%2Fprisma-read-replica-middleware/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/prisma","download_url":"https://codeload.github.com/prisma/prisma-read-replica-middleware/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/prisma%2Fprisma-read-replica-middleware/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29545589,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-17T13:00:00.370Z","status":"ssl_error","status_checked_at":"2026-02-17T12:57:14.072Z","response_time":100,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-11T18:16:06.387Z","updated_at":"2026-02-17T13:32:15.367Z","avatar_url":"https://github.com/prisma.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Prisma Read Replica Middleware\n\nWe have provided this middleware as an example only, and without warranty. It is not intended for use in a production environment. Please consider the limitations documented below before adding it to your application.\n\nFind implementation examples [here](https://github.com/prisma/middleware-examples/). \n\n## Installation\n\n1. `npm i @prisma/prisma-read-replica-middleware --save`\n\n## Usage\n\n1. Create a new file adjacent to your `schema.prisma` called `read-replica-schema.prisma`.\n2. Inside `read-replica-schema.prisma` add _only_ `generator` and `datasource` blocks.\n3. In the `generator` block, set `output` to `read-replica-client`.\n4. In the `datasource` block, add the URL of your read replica database.\n5. As part of your build process locally and in all environments, run `prisma-read-replica generate` to generate the Read Replica client.\n6. Wherever you instantiate Prisma using `new PrismaClient()`, instantiate `PrismaReadReplica` and apply it with `$use`. For example:\n\n```ts\nimport { Prisma, PrismaClient } from '@prisma/client'\nimport PrismaReadReplicaMiddleware from 'prisma-read-replica-middleware';\n\nconst modelsToExclude = ['User'];\n\nprisma.$use(PrismaReadReplicaMiddleware(modelsToExclude));\n```\n\n## Limitations\n\n1. This middleware does not perform migrations against a read replica database.\n2. This middleware only intercepts the following actions: find, findMany, findUnique\n3. This middleware does not account for custom providers.\n4. This middleware does not account for nested reads because middleware does not have access to the underlying SQL query. In the following example the request will _not_ be sent to the Read Replica because `User` is an excluded model.\n\n```ts\nimport { Prisma, PrismaClient } from '@prisma/client'\nimport PrismaReadReplicaMiddleware from 'prisma-read-replica';\n\nconst prisma = new PrismaClient({\n  log: ['query', 'info', 'warn', 'error'],\n});\n\nconst modelsToExclude = ['User'];\n\nprisma.$use(PrismaReadReplicaMiddleware(modelsToExclude));\n\nconst getUsers = await prisma.user.findMany({\n  where: {\n    email: {\n      contains: 'test',\n    },\n  },\n  include: {\n    post: true,\n  },\n})\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprisma%2Fprisma-read-replica-middleware","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fprisma%2Fprisma-read-replica-middleware","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprisma%2Fprisma-read-replica-middleware/lists"}