Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@prisma/prisma-read-replica-middleware

Package Overview
Dependencies
Maintainers
13
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@prisma/prisma-read-replica-middleware

  • 0.0.3
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
1
Maintainers
13
Weekly downloads
 
Created
Source

Prisma Read Replica Middleware

We 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.

Find implementation examples here.

Installation

  1. npm i @prisma/prisma-read-replica-middleware --save

Usage

  1. Create a new file adjacent to your schema.prisma called read-replica-schema.prisma.
  2. Inside read-replica-schema.prisma add only generator and datasource blocks.
  3. In the generator block, set output to read-replica-client.
  4. In the datasource block, add the URL of your read replica database.
  5. As part of your build process locally and in all environments, run prisma-read-replica generate to generate the Read Replica client.
  6. Wherever you instantiate Prisma using new PrismaClient(), instantiate PrismaReadReplica and apply it with $use. For example:
import { Prisma, PrismaClient } from '@prisma/client'
import PrismaReadReplicaMiddleware from 'prisma-read-replica-middleware';

const modelsToExclude = ['User'];

prisma.$use(PrismaReadReplicaMiddleware(modelsToExclude));

Limitations

  1. This middleware does not perform migrations against a read replica database.
  2. This middleware only intercepts the following actions: find, findMany, findUnique
  3. This middleware does not account for custom providers.
  4. 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.
import { Prisma, PrismaClient } from '@prisma/client'
import PrismaReadReplicaMiddleware from 'prisma-read-replica';

const prisma = new PrismaClient({
  log: ['query', 'info', 'warn', 'error'],
});

const modelsToExclude = ['User'];

prisma.$use(PrismaReadReplicaMiddleware(modelsToExclude));

const getUsers = await prisma.user.findMany({
  where: {
    email: {
      contains: 'test',
    },
  },
  include: {
    post: true,
  },
})

FAQs

Package last updated on 09 May 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc