6.0.0 • Published 10 months ago
@joggr/fastify-prisma v6.0.0
fastify-prisma
Fastify Prisma plugin to share the same PrismaClient across your entire server.
const allTheDucks = await server.prisma.rubberDucky.findMany();Getting Started
Before using this plugin you will need to have prisma set up. Once you are all set with prisma install the package and register the plugin on your server.
Install the package
npm
$ npm i @joggr/fastify-prismayarn
$ yarn add @joggr/fastify-prismaRegister the plugin
You have two options for registering the plugin:
- Use the plugin as-is or pass in your own configs
- Create a separate client and pass it in (great if you are using a monorepo or other more unique use cases)
javascript
const { PrismaClient } = require('@prisma/client');
const fastifyPrisma = require('@joggr/fastify-prisma');
// Default
await fastify.register(fastifyPrisma);
// With client
await fastify.register(fastifyPrisma, {
client: new PrismaClient(),
});
// with options
await fastify.register(fastifyPrisma, {
clientConfig: {
log: [{ emit: 'event', level: 'query' }]
}
});typescript
import { PrismaClient } from '@prisma/client';
import fastifyPrisma from '@joggr/fastify-prisma';
// Default
await fastify.register(fastifyPrisma);
// With client
await fastify.register(fastifyPrisma, {
client: new PrismaClient(),
});
// with options
await fastify.register(fastifyPrisma, {
clientConfig: {
log: [{ emit: 'event', level: 'query' }]
}
});Accessing the prisma client
async function somePlugin (server, opts) {
const ducks = await server.prisma.rubberDucky.findMany();
// do something with the ducks, log for now
server.log.warn({ ducks }, "🐥🐥 There are lots of ducks! 🐥🐥");
}License
Licensed under MIT.
5.2.1
11 months ago
5.2.0
1 year ago
5.0.0
1 year ago
6.0.0
10 months ago
4.1.0
1 year ago
4.0.0
1 year ago
3.0.1
2 years ago
3.0.0
2 years ago
2.2.1
2 years ago
2.2.0
2 years ago
2.1.1
2 years ago
2.2.2
2 years ago
2.1.0
2 years ago
2.0.1
2 years ago
2.0.0
2 years ago
1.2.3
2 years ago
1.2.2
2 years ago
1.2.1
2 years ago
1.2.0
2 years ago
1.1.1
2 years ago
1.1.0
2 years ago
1.0.4
2 years ago
1.0.3
2 years ago
1.0.2
2 years ago
1.0.1
3 years ago
1.0.0
3 years ago
0.2.0
3 years ago
0.1.0
3 years ago