Giter Site home page Giter Site logo

joggrdocs / fastify-prisma Goto Github PK

View Code? Open in Web Editor NEW
17.0 1.0 3.0 237.56 MB

Fastify Prisma plugin to share the same PrismaClient across your entire server.

Home Page: https://npmjs.com/@joggr/fastify-prisma

License: MIT License

JavaScript 8.68% Shell 1.10% TypeScript 90.22%
fastify fastify-plugin prisma

fastify-prisma's Introduction

fastify-prisma

CI npm version js-semistandard-style

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-prisma

yarn

$ yarn add @joggr/fastify-prisma

Register the plugin

You have two options for registering the plugin:

  1. Use the plugin as-is or pass in your own configs
  2. 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.



Want to sign up for Joggr?

We'd love to have you join, but we are in closed beta.
You can join our waitlist below.

fastify-prisma's People

Contributors

zrosenbauer avatar dependabot[bot] avatar scotty-robot avatar guladima avatar fdawgs avatar alex-popov-tech avatar github-actions[bot] avatar

Stargazers

Chase Holdren avatar Andy avatar Nitin Gupta avatar Nurul Sundarani avatar Thiago Porto avatar Tayeb avatar rgehbt avatar Nathanael Ferreira avatar Muhammad Ubaid Raza avatar Fabian avatar  avatar _.fmendes._ avatar beeman avatar Alex Ruheni avatar Nikolas avatar Christian Mathiesen avatar  avatar

Watchers

Seth Rosenbauer avatar

fastify-prisma's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.