https://github.com/losefor/prisma-redis-caching
add: caching functionality for prisma ORM with only one line of code
https://github.com/losefor/prisma-redis-caching
Last synced: 6 months ago
JSON representation
add: caching functionality for prisma ORM with only one line of code
- Host: GitHub
- URL: https://github.com/losefor/prisma-redis-caching
- Owner: losefor
- Created: 2021-11-10T08:05:49.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2021-11-21T11:46:15.000Z (almost 4 years ago)
- Last Synced: 2024-04-25T02:25:29.816Z (over 1 year ago)
- Language: TypeScript
- Size: 131 KB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
cache your project with prisma and redis with single line of code and without the hassle of
implementing it by you own self### Installation
- if you use npm :
```bash
npm i prisma-redis-caching
```
- if you use npm :
```bash
yarn add prisma-redis-caching
```### Usage
- import the package into your own project
```ts
import { createCachingMiddleware } from 'prisma-redis-caching';
```- after you instantiate the `prismaClient()` create the cachingMiddleware by providing the `createCachingMiddleware` function the redis instance as the first parameter and caching configuration in the second parameter
```ts
const cachingMiddleware = createCachingMiddleware<
Prisma.ModelName,
Prisma.PrismaAction
>(redis, [
{
model: 'City',
actions: ['findMany'],
},
{
model: 'Category',
actions: ['findMany'],
},
]);
```## configuration
you can provide configuration the middleware creator which is an array of objects each object you can provide the model that you want to cache it with the actions that will happens
|Props| type|
|-----|-----|
|model| any |
|actions|any|NOTE: you can provide generics as the example above to have the proper intellisense
- Finally provide the cacheMiddleware into prisma middleware
```ts
prisma.$use(cachingMiddleware);
```- Have fun :roll_eyes: