@lamware/prisma
v2.0.1
Published
Lamware Middleware for initializing and memoizing Prisma ORM
Downloads
43
Readme
This Lamware Middleware allows you to initialize and memoize your Prisma Client.
Installation
This package is available via NPM:
yarn add @lamware/prisma
# or
npm install @lamware/prisma
Usage
import type { APIGatewayProxyHandlerV2 } from 'aws-lambda';
import { PrismaClient } from '@prisma/client';
import { prisma } from '@lamware/prisma';
import { lamware } from '@lamware/core';
const { handler } = lamware<APIGatewayProxyHandlerV2<any>>()
// You can provide your PrismaClient directly.
.use(prisma(PrismaClient))
// Or an (a)synchronous set-up closure.
.use(prisma(async () => {
return new PrismaClient();
}))
.execute(async ({ state }) => {
const user = await state.prisma.user.findUnique({
where: { id: 1 },
});
return { statusCode: 200 };
});
export { handler };